Home | Gaming | Programming | Play Online | Submit Article | Submit BETA | Advertise | Contact | Keyword Query | Trade Games
Games++ Games & Game Programming

GAMES++
Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

BROWSER UTILITIES
E-mail This Page
Add to Favorites

SITE SEARCH

Web Games++

AFFILIATES
Cheat Codes
Trickster Wiki
Game Ratings
Trade Games
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials
Tutorial Bus
Fresh Tutorials

ADVERTISEMENT

Access An Enclosing Class From An Inner Class

Java: How To

public class TestIt 
{
   public static void main(String a[])
   {
      new TestIt().doit();
   }

   public void doit() 
   {
      new InnerClass().sayHello();
   }

   public void enclosingClassMethod()
   {
      System.out.println("Hello world!");
   }

   class InnerClass 
   {
      public void sayHello() 
      {
         TestIt.this.enclosingClassMethod();
      }
   }
}

OR

public class TestIt 
{
   TestIt testItClass = this;
   public static void main(String a[])
   {
      new TestIt().doit();
   }

   public void doit() 
   {
      new InnerClass().sayHello();
   }

   public void enclosingClassMethod()
   {
      System.out.println("Hello world!");
   }

   class InnerClass 
   {
      public void sayHello() 
      {
         testItClass.enclosingClassMethod();
      }
   }
}

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy