"Thinking in Java" interface and internal class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.