What is static variable and static method?

Answers were Sorted based on User's Feedback



What is static variable and static method?..

Answer / niranjanravi

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 ?    268 Yes 54 No

What is static variable and static method?..

Answer / mallesh

A static variable is a variable who's single copy in memory
is shared by all objects,so any modifications to the static
variable will modify it's value in all objects.

Static variables are created in Method Area part of Memory.

Is This Answer Correct ?    147 Yes 30 No

What is static variable and static method?..

Answer / venkat

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 ?    90 Yes 49 No

What is static variable and static method?..

Answer / naraen

static variable is a class variable. This life time scope
in whole prgm...

static method is use to access without creating object in
the java prgm...

Is This Answer Correct ?    53 Yes 26 No

What is static variable and static method?..

Answer / viral

class A
{ static int a;
}

class StaticDemo
{ public static void main(String args[])
{ A obj1 = new A();
A obj2 = new A();
}
}

In such a case, objects obj1 and obj2 will not have
different copies of variable a. Both objects will refer to
the same "a". In simpler words, copy of "a" is not created.

If "a" was not static, then obj1 and obj2 would hold
different copies of "a".

Is This Answer Correct ?    14 Yes 0 No

What is static variable and static method?..

Answer / radhika.rangu

Static variable:-static variable is a variable whose single
copy is shared by all the objects of a class.
Static Method:-static method is a method.It is used to
declare the keyword called static.No need to create the
Objects.It is called without creating the object

Is This Answer Correct ?    14 Yes 1 No

What is static variable and static method?..

Answer / abnish kumar rajput

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 ?    28 Yes 17 No

What is static variable and static method?..

Answer / santosh

Ordinarily, when you create a class you are describing how
objects of that class look and
how they will behave. You don’t actually get anything until
you create an object of that
class with new, and at that point data storage is created
and methods become available.
But there are two situations in which this approach is not
sufficient. One is if you want to
have only one piece of storage for a particular piece of
data, regardless of how many objects
are created, or even if no objects are created. The other
is if you need a method that isn’t
associated with any particular object of this class. That
is, you need a method that you can
82 Thinking in Java www.BruceEckel.com
call even if no objects are created. You can achieve both
of these effects with the static
keyword. When you say something is static, it means that
data or method is not tied to any
particular object instance of that class. So even if you’ve
never created an object of that class
you can call a static method or access a piece of static
data. With ordinary, non-static data
and methods you must create an object and use that object
to access the data or method,
since non-static data and methods must know the particular
object they are working with.
Of course, since static methods don’t need any objects to
be created before they are used,
they cannot directly access non-static members or methods
by simply calling those other
members without referring to a named object (since non-
static members and methods must
be tied to a particular object).

Is This Answer Correct ?    24 Yes 13 No

What is static variable and static method?..

Answer / govardhani

A static variable is a variable who's single copy in memory
is shared by all objects,so any modifications to the static
variable will modify it's value in all objects.

In classes, a static method is one that is called without an
instance of that class, while a non-static method is called
by instances of the class.

Is This Answer Correct ?    9 Yes 0 No

What is static variable and static method?..

Answer / nithya

Static Variable:
A variable that can be accessed by any class.
Eg:
class Add
{
static int a; // Defaultly the value of a is 0 since,it
is declared as static.
}
class Sub
{
int A=Add.a; // the value of A is 0.
}


Static Method:
if the method is declared as Static then its variable
should be also declared as static and static method can be
accessed with the help of class name rather than object name

eg:

class Addition
{
public static void Add()
{
}
}
class Subraction
{
Addition.Add();
}

Is This Answer Correct ?    4 Yes 1 No

Post New Answer

More Core Java Interview Questions

What about static nested classes in java?

0 Answers  


I want to re-reach and use an object once it has been garbage collected. How it's possible?

0 Answers  


What is main string [] args?

0 Answers  


What is the function of java?

0 Answers  


Difference between interface and abstract class with ex.

4 Answers   Cognizant, Tech Mahindra,






Thanks A.jyotsna, Can u tell me differnce between abstract class and interface vikash

4 Answers  


What is the meaning of 3 dots in java?

0 Answers  


Write a program to create a binary Tree ?

2 Answers  


What is an immutable class?

0 Answers  


Where are register variables stored?

0 Answers  


What will happen inside init() in servlet. my interviewer asked servlet lifecycle. i said "once servlet is loaded in to memory init() will be called which performs servlet initialization " . Again interview asked what values will be initialized . what is difference between init() and init(ServletConfig config).

2 Answers   Infinite Computer Solutions, TCS,


How many characters is 2 bytes?

0 Answers  


Categories