Difference between revisions of "Inner Classes"

From Suhrid.net Wiki
Jump to navigationJump to search
(Created page with "* Inner classes have access to members of the outside classes. * Think of the Inner class as sort of a MEMBER of the outer class. * This means that regular Inner classes '''cann...")
 
Line 6: Line 6:
  
 
<syntaxhighlight lang="java5">
 
<syntaxhighlight lang="java5">
 +
 +
class Outer {
 +
  class Inner() {
 +
 +
  }
 +
}
 +
 
Outer o = new Outer();
 
Outer o = new Outer();
 
Outer.Inner i =  o.new Inner()
 
Outer.Inner i =  o.new Inner()
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 02:55, 4 June 2011

  • Inner classes have access to members of the outside classes.
  • Think of the Inner class as sort of a MEMBER of the outer class.
  • This means that regular Inner classes cannot have any statics (variables or methods)
  • Only way to access an instance of the inner classes is through an instance of the outer class.
  • Remember the funny syntax:
class Outer {
  class Inner() {

  }
}

Outer o = new Outer();
Outer.Inner i =  o.new Inner()