Examples in the book
After the adaptation.
1 Packagetest2;2 3 classa{4 Interfaceb{voidf ();}5 Public classBimpImplementsb{ Public voidf () {}}6 Private classBImp2Implementsb{ Public voidf () {}}7 8 Public Interfacec{voidf ();}9 classCimpImplementsc{ Public voidf () {}}Ten Private classCImp2Implementsc{ Public voidf () {}} One A Private Interfaced{voidf ();} - Private classDimpImplementsd{ Public voidf () {}} - Public classDImp2Implementsd{ Public voidf () {}} the - PublicD getd () {return NewDImp2 ();} - PrivateD DRef; - Public voidReceiveD (d d) {dref=d;dref.f ();} + - } + Interfacee{ A Interfaceg{voidf ();} at - Public Interfaceh{voidf ();} - voidg (); - } - Public classnestinginterfaces { - in Public classBimpImplementsa.b{ Public voidf () {}} - classCimpImplementsa.c{ Public voidf () {}} to + //The type A.D is not visible - //class Dimp implements A.d{public void F () {}} the * classEimpImplementse{ Public voidg () {}} $ classEgimpImplementse.g{ Public voidf () {}}Panax Notoginseng - classEImp2Implementse{ the Public voidg () {} + classEGImplementse.g{ Public voidf () {}} A } the + Public Static voidMain (string[] args) { -A a=NewA (); $ $ //The type A.D is not visible - //A.D ad=a.getd (); - the //Type Mismatch:cannot convert from A.D to A.DIMP2 - //a.dimp2 di2=a.getd ();Wuyi theA.DIMP2 di2=(A.DIMP2) a.getd (); -System.out.println (Di2.getclass (). GetName ());//test2. A$DIMP2 Wu - //The type A.D is not visible About //a.getd (). f (); $ - ( (A.DIMP2) a.getd ()). f (); - -A a2=NewA (); A a2.received (a.getd ()); + } the -}
can run smoothly.
"Thinking in Java" interface and internal class