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

Is java se free?

524


What are different data types?

568


What is a conditional statement explain with example?

543


What are keywords give examples?

582


How many bytes is a string?

561






How transient variable is different from volatile variable?

562


Can we restart a dead thread in java?

554


What is the simpletimezone class in java programming?

538


What is %d in printf?

531


Can one thread block the other thread?

606


difference between byte stream class and character stream class?

4083


Highest level event class of the event-delegation model?

3503


What is meant by oops concept in java?

507


What is parsing in grammar?

560


How to calculate the length of a singly linked list in java?

584