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

Which are the two subclasses under exception class?

525


Is boolean a data type in java?

516


What do u mean by variable?

559


What is the file type?

551


How does map works in java?

507






What is the difference between char and char *?

561


How do you check if two given string are anagrams?

551


What is java string pool?

539


Explain about version control?

585


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

2132


What are scalar data types?

521


What language is an assembler written in?

546


Is arraylist dynamic in java?

513


What is a literal coding?

508


Is java platform independent?

563