Difference between revisions of "Inner Classes"

From Suhrid.net Wiki
Jump to navigationJump to search
Line 16: Line 16:
 
Outer.Inner i =  o.new Inner()
 
Outer.Inner i =  o.new Inner()
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
[[Category:OCPJP]]

Revision as of 02:56, 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()