Home arrow static arrow Java Programming [Archive] - Protected Inner Classes
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Protected Inner Classes
This topic has 1 reply on 1 page.

Posts:18
Registered: 8/9/04
Protected Inner Classes  
Aug 9, 2004 3:32 PM



 
Having difficulty debugging the following:

pkg1;  public interface I1 { void method1(); }------------------------------------------  pkg2:   import pgk1.*;        public class C2         {            protected int i2 = 2;            protected class C2Inner1 implements I1            {                 public void method1()                     { System.out.println("This is C2Inner1.method1."); }            }        }------------------------------------------  pkg3:   import pgk1.*;        import pgk2.*;        class C3 extends C2        {            I1 createC2Inner1()             {                 C3 z = new C3();                              return z.new C2Inner1();                // Line 1                //  return new C2Inner1();              // Line 2                //  return new C3.C2Inner1();           // Line 3                //  return new z.C2Inner1();            // Line 4            }            public static void main(String[] args)            {                C3 a = new C3();                a.i2 = 3;                               // Line 5                 I1 x = a.createC2Inner1();                x.method1();            }        }/*Line 5 runs okay, which indicates that my understanding of protected is ok.Lines 1 through 4 all cause the same compile error:    C2Inner1() has protected access in pkg2.C2.C2Inner1    When I change C2Inner1 access to public, Lines 1 through 4 each work okay.Why can I access i2 but not C2Inner1 (i.e. when both protected)?  Is theredifferent syntax to handle this specific situation?    /*
 

Posts:2,830
Registered: 9/1/03
Re: Protected Inner Classes  
Aug 9, 2004 4:58 PM (reply 1 of 1)



 
this.new Inner() ?
 
This topic has 1 reply on 1 page.