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 are the three parts of a lambda expression? What is the type of lambda expression?
Why is a singleton bad?
Is java 9 released?
Explain why wait(), notify() and notifyall() methods are in object class rather than in thread class?
What is internal iteration in java se 8?
What do you mean by checked exceptions?
Explain super keyword in java.
What is this keyword in java?
How to perform merge sort in java?
What is the purpose of using javap?
Which access specifier can be used with class ?
What is java util collection?
What is nextint java?
What are the differences between abstract class and interface?
What is the difference between the paint() and repaint() methods in java programming?