Anonymous internal class, member class, and local class

Source: Internet
Author: User

Today, I saw several concepts in the Code: internal class, local class, member class, static member class, and anonymous internal class. I felt confused in an instant. Below is a small example to illustrate them:

Public class classtest {public static void main (string [] ARGs) {classtest son = new classtest (); // test the Anonymous class son. testanonymous (New anonymousclass () {@ override public void test () {system. out. println ("1->" + this. getclass (). ismemberclass (); system. out. println ("1->" + this. getclass (). isanonymousclass (); system. out. println ("1->" + this. getclass (). islocalclass (); system. out. println ("-------------------------------------") ;}}); // test the member class son. testmember (); // test the static member class new staticmemberclass (); // test the local class localclass {public localclass () {system. out. println ("4->" + this. getclass (). ismemberclass (); system. out. println ("4->" + this. getclass (). isanonymousclass (); system. out. println ("4->" + this. getclass (). islocalclass (); system. out. println ("-------------------------------------") ;}} new localclass () ;}private void testanonymous (anonymousclass inner) {inner. test ();} private void testmember () {New memberclass ();}/*** interface, used to test the internal class * @ author xinghzhang **/interface anonymousclass {public void test ();} /*** static member class ** @ author xinghzhang **/static class staticmemberclass {public staticmemberclass () {system. out. println ("3->" + this. getclass (). ismemberclass (); system. out. println ("3->" + this. getclass (). isanonymousclass (); system. out. println ("3->" + this. getclass (). islocalclass (); system. out. println ("-----------------------------------");}/*** member class ** @ author xinghzhang **/class memberclass {public memberclass () {system. out. println ("2->" + this. getclass (). ismemberclass (); system. out. println ("2->" + this. getclass (). isanonymousclass (); system. out. println ("2->" + this. getclass (). islocalclass (); system. out. println ("---------------------------------------");}}}



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.