1. Use static to declare an inner class that can be invoked directly outside the
[Java] View plain copy class outer{ // define outer class private static String info = "Hello world" ; // define private properties for external classes static class inner{ // use static to define inner class as outer class public void print () { Methods for defining internal classes SYSTEM.OUT.PRINTLN (Info) ; // Direct access to the private properties of external classes } }; public void fun () { // methods for defining external classes new inner (). Print () ; // invoking methods via internal class-instantiated objects } }; public class InnerClassDemo03{ public static void main ( String args[]) { new outer.inner (). Print () ; / / calls the fun () method of the outer class } };
2. Do not use STATC to declare an inner class, so that the external call
[Java] View plain copy class outer{ // define outer class private String info = "Hello world" ; // define private properties for external classes class Inner{ // Define inner class public void print () { // ways to define inner classes             SYSTEM.OUT.PRINTLN (info) ; // direct access to private properties of external classes } }; public void fun () { // defines the method of the outer class new inner (). Print ( ) ; // Object Invocation Method } }; public class by internal class instantiation innerclassdemo04{ public static void main (String args[) ) { outer out = new outer () ; // External Class instantiation object outer.inner in = out.new inner () ; // instantiation of internal class objects in.print () ; //  Method of calling Inner class } };
3. Define the inner class in the method so that the outer call
[Java] view plain Copy class outer{//define an external class