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


Please Help Members By Posting Answers For Below Questions

How can we make copy of a java object?

546


How can constructor chaining be done using this keyword?

589


What is the difference between length and size in java?

499


What is meant by null and void?

538


What are the 7 types of characters?

566






Is node a data type in java?

499


What is the primitive type byte?

585


Explain the pointers in Java?

596


What is method overloading in java ?

556


What is the relationship difference the canvas class and the graphics class?

560


How would overload a function based on return type?

548


What is the difference between actual and formal parameters?

516


What does += mean coding?

515


What is http client in java?

520


What is a data structure java?

504