Thursday, April 10, 2014

What is Inner Class ?

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:

ashu said...

Why statis variables are not allowed in inner classes?

Vicky said...

What's the purpose of inner classes. How they are invoked. Few examples will be really good to understand this.

Post a Comment

 
| ,