S
Steve Schooler
This query best viewed with fixed font.
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
C1return z.new C2Inner1();
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 there
different syntax to handle this specific situation?
/*
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
C1return z.new C2Inner1();
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 there
different syntax to handle this specific situation?
/*