java main method can also be called by other methods

public class MainMethod4 {
    public static int times = 5;
    public static void main(String[]args) {
        System.out.println(+times+"times transfer left");
        if (times <= 0) {
            System.exit(0);
        }
        main2(args);
        
        
    }
    public static void main2(String[]args) {
        times--;
        main(args);
        
    }

}

Run shot

 In this example, the main method main2 call, call in the main method main2 process, resulting in an indirect recursive calls. Static variable times for specifying the number of recursive calls.

 The results showed that the main method of operation is called five times

Guess you like

Origin www.cnblogs.com/YanJieMao/p/11482587.html