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


Please Help Members By Posting Answers For Below Questions

Why strings in java are called as immutable?

671


What are the advantages of autoboxing?

635


What is variable and constant explain with example?

665


What is data structure in java?

622


Is ++ operator is thread safe in java?

604






Which variables are stored in stack?

544


What is an interface in java?

659


What is fundamental datatype?

618


What advantage do java's layout managers provide over traditional windowing systems?

632


Explain the difference between map and flatmap stream operation?

910


Why do we create public static method in java?

675


What are the different types of garbage collectors in java?

651


What are the properties of thread?

572


What is charat ()?

619


How does a for loop work java?

645