dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]How do you simulate an inner class in C#?


From: Mohan Embar
Subject: Re: [DotGNU]How do you simulate an inner class in C#?
Date: Mon, 26 May 2003 21:07:09 -0500

Gopal,

>> They can be accessible from outside (public class Inner) - I think they're
>> like nested classes with the outer this pointer. ^Tum?
>
>No I just tried it ... they have to called from a context where the 
>"this" is the direct enclosing class of Inner ..

I compiled and ran the following under JDK 1.4.1:

InnerTest.java
--------------------------------8<-----------------------------------
public class InnerTest
{
private int x = 10;

   public class Inner
   {
   public void printX()
   {
      System.out.println(x);
   }
   }

   public Inner createInner()
   {
      return new Inner();
   }
}
--------------------------------8<-----------------------------------

Main.java
--------------------------------8<-----------------------------------
public class Main
{
public static void main(String[] args)
{
   InnerTest aInnerTest = new InnerTest();
   InnerTest.Inner aInner = aInnerTest.createInner();
   aInner.printX();
}
}
--------------------------------8<-----------------------------------

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/






reply via email to

[Prev in Thread] Current Thread [Next in Thread]