Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

12. Getting GUI: A Very Graphic Story > An inner class instance must be tied to...

An inner class instance must be tied to an outer class instance[12]

Note

An inner object shares a special bond with an outer object.

image with no caption

Remember, when we talk about an inner class accessing something in the outer class, we’re really talking about an instance of the inner class accessing something in an instance of the outer class. But which instance?

Can any arbitrary instance of the inner class access the methods and variables of any instance of the outer class? No!

An inner object must be tied to a specific outer object on the heap.

image with no caption
  1. Make an instance of the outer class

    image with no caption
  2. Make an instance of the inner class, by using the instance of the outer class.

    image with no caption
  3. The outer and inner objects are now intimately linked.

image with no caption

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial