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