What is difference between static method and static
variable?

Answers were Sorted based on User's Feedback



What is difference between static method and static variable?..

Answer / kusum

if a variable is declared static only single copy is
visible to all instances of class.if a method is declared
as static it is executed first as how main method is
executed in java

Is This Answer Correct ?    22 Yes 9 No

What is difference between static method and static variable?..

Answer / priyabrata patro

first let us see what is method and variable.
method is nothing but a functionality which is collection of statement.But variable is a container which contains data.
second is what is the usage of static keyword.
By using static keyword you can save memory , i mean if you declare one non static member than while creating object it will occupie memory but once you have declared one member as a static , it will not allocate memory number times rather than once.
ok , now let us find out about our question.
static mehod contains statements and where exactly you can use static variable.And it can be invoked by any methods only.
And static variable contains data which can be modified by any methods.And it can be used by method and also other variable. And one main thing about static variable is you can declare a static member as local variable.

Sorry , i could not be able to declare about static . ok , if you want to know more than contact me in this mail id priyabrata.try@gmail.com

Is This Answer Correct ?    13 Yes 1 No

What is difference between static method and static variable?..

Answer / kalandi sahoo

static variable is uniqe copy of in memory.that is every
object is share the static variable.

Is This Answer Correct ?    9 Yes 0 No

What is difference between static method and static variable?..

Answer / jimm

static variable can be used by static as well as non-static
method.
and static method only uses static variable

Is This Answer Correct ?    12 Yes 8 No

What is difference between static method and static variable?..

Answer / archana

if we declare a variable as static then it has only one copy
for all classes. if a method is declared as static without
using object we can call it.

Is This Answer Correct ?    11 Yes 9 No

What is difference between static method and static variable?..

Answer / joh-b tanzania

The static keyword denotes that a member variable, or method, can be accessed without requiring an instantiation of the class to which it belongs.

In simple terms, it means that you can call a method, even if you've never created the object to which it belongs! Every time you run a stand-alone application (which requires a static main method), the virtual machine can call the main method without creating a new application object. Of course, unless the application's methods are all static, you will need to create an instance of it at some point.

With regard to member variables, it means that they can be read from, and written to, without creating an object. You may have noticed that many classes create constants that can be read, without creating an object.

static final int VERSION = 2;

Static member variables are shared by all instances of the class to which they belong. When writing classes, this can be a handy feature. Consider the following example, where a counter is used to track how many myObject instantiations have taken place.

public class myObject
{
static int objectCount = 0;

public myObject()
{
objectCount++;
}

public String toString()
{
return new String ("There are " + objectCount + " objects");
}
}

Is This Answer Correct ?    3 Yes 1 No

What is difference between static method and static variable?..

Answer / n.siddardh

static variable copy is available to every object in the
memory if we change one value in an object there no effect
inother objects,and if we declare a method as static that
will be executed by the JVM like main method
The execution of JVM
1.static block
2.static methods
3.Instance methods

Is This Answer Correct ?    7 Yes 12 No

Post New Answer

More Core Java Interview Questions

What is a data structure java?

0 Answers  


Can a class have more than one object?

0 Answers  


how do I create a runnable with inheritance? : Java thread

0 Answers  


what is a transient variable?

5 Answers  


What is the purpose class.forname method?

0 Answers  






In which language JVM (Java Virtual Machine) is implemented

5 Answers  


What do you mean by static variable?

0 Answers   TCS,


what is the main class of all the classes

5 Answers   Photon,


What is the difference between access specifiers and access modifiers in java?

0 Answers  


How do I write a self declaration?

0 Answers  


How do you check if a number is a perfect square?

0 Answers  


What are the two ways of implementing multi-threading in java?

1 Answers  


Categories