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
Can we override private methods?
Is java platform independent?
What are the different ways of implementing thread? Which one is more advantageous?
How do you calculate square roots?
Where are global variables stored?
What are different types of encoding?
how would you implement a thread pool? : Java thread
What is the difference between a window and a frame in java programming?
Which oo concept is achieved by using overloading and overriding?
What is the arraylist in java?
What is a condition in programming?
What kind of variables can a class consist?
How do you compare values in java?
What are inbuilt functions in java?
Why webdriver is an interface?