What is static variable and static method?
Answer Posted / nithya
Static Variable:
A variable that can be accessed by any class.
Eg:
class Add
{
static int a; // Defaultly the value of a is 0 since,it
is declared as static.
}
class Sub
{
int A=Add.a; // the value of A is 0.
}
Static Method:
if the method is declared as Static then its variable
should be also declared as static and static method can be
accessed with the help of class name rather than object name
eg:
class Addition
{
public static void Add()
{
}
}
class Subraction
{
Addition.Add();
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What is use of super keyword?
What are the types of methods in java?
Is java 11 paid version?
What is the significance of listiterator?
How to handle a web browser resize operation?
What is string intern in java?
What is the difference between yielding and sleeping?
What is regex java?
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
How many types of methods are there in java?
Name few java 8 annotations ?
Explain the differences between static and dynamic variables?
Is oracle charging for java?
State the significance of public, private, protected class?
What is a super method?