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
Does java trim remove newline?
How many types of memory areas are allocated by JVM in java?
What is treeset and treemap in java?
What is the use of string and stringbuffer?
Can we cast any other type to boolean type with type casting?
What are the advantages of unicode?
What are some alternatives to inheritance?
How to store image in arraylist in java?
When should I use singleton pattern?
Explain heap sort?
Why we cannot override static method?
What is a boolean output?
What is the use of arraylist in java?
How do you remove duplicates in java?
Can we convert list to set in java?