An
inner class is a class defined within another class. Other than a few
restrictions, mentioned in the text that follows, they are declared like
regular classes.
public
class MyClass {
String
x;
class
MyInnerClass {
String
y;
void
doSomething() {
//
cannot access x from here!
}
}
Inner
classes are always static, so the static keyword is not permitted.They can’t
reference variables in their containing class.Additionally, inner classes
cannot contain other inner classes and cannot contain static variables.
2 comments:
Why statis variables are not allowed in inner classes?
What's the purpose of inner classes. How they are invoked. Few examples will be really good to understand this.
Post a Comment