What is difference between static method and static
variable?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
What is a java applet? What is an interface?
What is a reflection package?
Can java arraylist hold different types?
What is an argument java?
Why do we need wrapper class?
What does null mean in java?
Difference between method overloading and method overriding in java ?
What is style and indentation?
why static class in java or what is use of static class in java
what ide u r using and wat version, how wil u build the project etc ?
What is the escape character in java?
How to convert string to char and vice versa?