简体   繁体   中英

Don't understand flow of contril

I have the following code:

public class Messages {
    public static void main (String[] args) {
        message1();
        message2();
        System.out.println("Done with main.");
    }

    public static void message1() {
        System.out.println("This is message1.");
    }

    public static void message2() {
        System.out.println("This is message2.");
        message1();
        System.out.println("Done with message2.");
    }   
}

Why does this print out Done with message2 first although the message1 function is called first?

You asked:

Why does this print out Done with message2 first?

It doesn't. On my computer your program prints:

This is message1.
This is message2.
This is message1.
Done with message2.
Done with main.

I suspect your problem is lying somewhere else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM