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 |
Difference between nested and inner classes ?
Can we overload final method in java?
What are the main uses of this keyword?
what is the difference between a java object reference and c++ pointer?
what is synchronization and why is it important? : Java thread
Can a class extend 2 classes in java?
Which is better 64 bit or 32 bit?
Is assembly language a low level language?
Nested classes VS Inner classes?
Why operator overloading is not in Java?
How do you sort data in java?
What is a string token?