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 is deadlock? : Java thread

0 Answers  


Which graphs are functions?

0 Answers  


What is the default access specifier for variables and methods of a class?

0 Answers  


What is the size of int?

0 Answers  


What is core java used for?

0 Answers  






Explain how can you debug the Java code?

0 Answers   BirlaSoft,


Can you achieve runtime polymorphism by data members?

0 Answers  


What is advantage of using threads?

2 Answers   BMC,


write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.

0 Answers   Axcend,


What is mutable object and immutable object?

0 Answers  


What's the access scope of protected access specifier?

0 Answers  


Can a method be static?

0 Answers  


Categories