What is local, member and class variable in java? - Java @ Desk

Monday, May 20, 2013

What is local, member and class variable in java?

1) Local variable is the one that is being declared inside a method. This variable is visible within the method only

2) Member variable is the one that is being declared at class level outside the methods. This variable is visible to the whole class.




3) Class variable is the one that has static keyword. This variable is created only once and can be accessed using .classVariableName.

public class Variables {
public String memberVariable;
public static String classVariable;

public void methodName() {
int localVariable = 0;
}
}






No comments:

Post a Comment