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
How can we make copy of a java object?
How can constructor chaining be done using this keyword?
What is the difference between length and size in java?
What is meant by null and void?
What are the 7 types of characters?
Is node a data type in java?
What is the primitive type byte?
Explain the pointers in Java?
What is method overloading in java ?
What is the relationship difference the canvas class and the graphics class?
How would overload a function based on return type?
What is the difference between actual and formal parameters?
What does += mean coding?
What is http client in java?
What is a data structure java?