What is static variable and static method?
Answers were Sorted based on User's Feedback
Answer / aditya
static variables are class variables.They are globally
declared with the keyword "static".They can be intialised at
the declaration time (or) they can be initialised in static
block.They can accessed by using thier class name
(class name.static variable name).Static variables can also
be accessed by the obj name but to make the difference
between the instance variables and static variables they are
accessed using class name outside the class.Static methods
are the methods that can access only static variables,they
can access instance variables also but only through the
object of the instance variables not directly.Their values
are stored in heap memory.Any changes to the static
variables reflect in heap memory.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / digant mehta
tatic variables are classes variables not instance
variables .They are instantianted only once for a
class.They are initialised at class load time.
Static method can be referenced with the name of the name
of the particular object of that class. That's how the
library methods like System.out.println works.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / kutta
a variable declared inside a method is local to that method.
it can't be accessed outside the method. if a variable
declared in a class means its a global variable.if we
declare a variable with static keyword in a class means it
can be accessed by all the class.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / qaisarayub
static variables are classes variables not instance
variables .They are instantianted only once for a
class.They are initialised at class load time.
Static method can be referenced with the name of the name
of the particular object of that class. That's how the
library methods like System.out.println works.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ahmad
Static variables are those variables that are declared with
static keyword of java.Static variables are declared once
into a class and are available entire class.Static variables
are common to all objects of class.Static variables can be
accessed by non-static methods.Whereas Static methods are
those which are declared with static keyword and can only be
accessed static variables.If we have Static method then we
can call it directly with class_name.And static variables
and methods both are related to class,whereas non-static
variables and methods are related to object.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ankit
static variable are those variable which call with the hepl
of the class name and they are not initiated.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rajiv sairam
Static variable can be modified, only a single copy is maintained for the objects,it stays in memory until we delete it manually,accessing is directly with the class name
Static method can access only static data with the class name, no need of creating objects.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / subhen
Have a look at the following post to uunderstand why do we
use static variable and static class in our programme.
http://blog.subhendu.info/index.php/why-to-use-static-
methods-class-and-static-variable/
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / bijeesh.p
A static variable ,also reffered to as a class variable
which exists across instances of a class.
By default,all variables are created as instance
variables(A variable related to a single instance of a
class.Each time an instance of a class is created,the
system creates one copy of the instance variables related
to that class).To make a class variable,you must explicitly
declare the variable static.
| Is This Answer Correct ? | 16 Yes | 18 No |
Answer / anupam sharma
static variables are classes variables not instance
variables .They are hold the value and instantianted only
once for a
class.They are initialised at class load time.
Static method can be referenced with the name of the name
of the particular object of that class. That's how the
library methods like System.out.println works.
| Is This Answer Correct ? | 16 Yes | 18 No |
Java openings 3 - 5 years, Lnt Infotech. requirements - core java, J2ee, struts, hibernate Interview Date:- 19 March 2011 Time:- 9:00 AM to 12:00 Pm Interview Location - L & T Infotech, Manapakkam, Chennai Refererral PS NO:- 291649 (Please mention this when u fill the form only then u will be considered for interview) Documents Required:- Latest Resume, Photograph and last 3 payslips Mail me on vasan2211@gmail.com once u appear for interview
What is args length in java?
Which programming language is most secure?
what is difference between excute query ()and execute update ()?
What is anagram in java?
What method is used to know the status of Checkbox(i.e it is checked or unchecked)?
what is the use of thread?Justify it by project point of view
what is mutability?which one is mutable String or StringBuffer?and why?give examples of each which shows the mutability of each String or StringBuffer
The following program reads data (details of students) from a file named students.txt and converts it into e-mail addresses. The results are written to a file named studentemail.txt. students.txt consists of a number of lines, each containing the data of a student in colon delimited format: Last Name:First Name:Student Number Each input record is converted to an e-mail address and written to studentemail.txt in the following format: the first character of the last name + the first character of the first name + the last four digits of the student number + “@myunisa.ac.za” import java.io.*; public class EmailConverter { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new FileReader ("students.txt")); PrintWriter output = new PrintWriter(new FileWriter ("studentemail.txt")); String line = input.readLine(); while (line != null) { // Extract the information for each student String[] items = line.split(":"); // Generate the email address String email = "" + items[0].charAt(0) + items[1].charAt(0) + items[2].substring(4,8) + "@myunisa.ac.za"; email = email.toLowerCase(); // Output output.println(email); line = input.readLine(); } input.close(); output.close(); } } Rewrite the class so that it handles possible errors that may occur. In particular, it should do the following: • It should catch at least three appropriate exceptions that might occur, and display suitable messages. • At this stage, the program will not run correctly if there is an empty line in the input file. Change the program so that if an empty line is encountered, an exception is thrown and the empty line is ignored. This exception should be handled with the display of a suitable error message. • Before the e-mail address is added to the output file, check if the student number has 8 digits. If not, throw an InvalidFormatException (which the program should not handle itself)
What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
What is the difference between JDBC 1.0 and JDBC 2.0?
Can we override static methods in java?