Java Inner Class - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Java Inner Class

Description:

An inner class is associated with an instance of its enclosing ... It cannot define any static ... Then, create the inner object within the outer object with ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 7
Provided by: Owne1495
Category:
Tags: class | define | inner | java

less

Transcript and Presenter's Notes

Title: Java Inner Class


1
  • Java Inner Class

2
Inner Class Definition
  • An inner class is associated with an instance of
    its enclosing class and has direct access to that
    object's methods and fields.
  • It cannot define any static members itself.
  • Objects that are instances of an inner class
    exist within an instance of the outer class.
  • class OuterClass
  • ...
  • class InnerClass ...

3
Inner Class
4
Inner Class (2)
  • To instantiate an inner class, you must first
    instantiate the outer class.
  • Then, create the inner object within the outer
    object with this syntax
  • OuterClass.InnerClass innerObject
  • outerObject.new InnerClass()

5
Inner Class Example
  • class myClass
  • static int j35
  • static class myHelper
  • int i10
  • public static void main (String args)
  • myClass.myHelper mh new
    myClass.myHelper()
  • myClass mc new myClass()
  • System.out.println (mh.i mc.j)

6
Inner Class Example(2)
  • class myClass
  • int i35
  • myClass ()
  • myClass_A a new myClass_A()
  • a.j15
  • ia.j
  • static class myClass_A
  • int j11
  • public static void main (String args)
  • myClass mc new myClass()
  • System.out.println (mc.i)
  • myClass.myClass_A mh new myClass.myClass_A()
  • System.out.println (mh.j)
Write a Comment
User Comments (0)
About PowerShow.com