What is static variable and static method?
Answer Posted / 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 |
Post New Answer View All Answers
Why strings in java are called as immutable?
What are the advantages of autoboxing?
What is variable and constant explain with example?
What is data structure in java?
Is ++ operator is thread safe in java?
Which variables are stored in stack?
What is an interface in java?
What is fundamental datatype?
What advantage do java's layout managers provide over traditional windowing systems?
Explain the difference between map and flatmap stream operation?
Why do we create public static method in java?
What are the different types of garbage collectors in java?
What are the properties of thread?
What is charat ()?
How does a for loop work java?