Go JAVA accesses internal classes, methods, and so on in main

Source: Internet
Author: User

1. Using static properties, methods, inner classes

1 classA2 {3     Static inti = 1;//static properties of Class A4     Static voidOutPut ()//static methods for Class A5     {6 System.out.println (i);7     }8     Static classB//static inner class of Class A9     {Ten         voidOutPut () One         { ASystem.out.println ("B"); -         } -     } the      Public Static voidMain (string[] args) -     { -          -System.out.println (i);//calling a static property +OutPut ();//calling a static method -b b =NewB ();//calling a static inner class + b.output (); A     } at}

2. Use the object name of this class to access

1 classA2 {3     inti = 1;//Properties4     voidOutPut ()//Method5     {6 System.out.println (i);7     }8     classB//Inner class9     {Ten         voidOutPut () One         { ASystem.out.println ("B"); -         } -     }     theB Newb ()//(key) to create a B object in a dynamic method -     { -b b =NewB (); -         returnb; +     }     -      Public Static voidMain (string[] args) +     { AA A =NewA (); atSystem.out.println (A.I);//Call Properties -A.output ();//Calling Methods -b b = A.newb ();//calling inner class - b.output (); -     } -}

In static main, you cannot create a non-static inner class.

Go JAVA accesses internal classes, methods, and so on in main

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.