30/09/2018, 21:23
Hỏi về Thứ tự chạy câu lệnh trong Singleton pattern
- cho class:
public class Menu {
1 . . . .private static final Menu mn = new Menu();
2 . . . .private final String name = “Name Menu”;
3 . . . .private Menu() {}
4 . . . .public static Menu getMn() {
5 . . . . . . . .return mn;
6 . . . .}
7 . . . .public String getName() {
8 . . . . . . . .return name;
9 . . . .}
}
Menu p=Menu.getMn(); --> em cần chạy câu lệnh này .Ai có thể giải thích giúp em thứ tự chạy lệnh trong class Menu được không
Bài liên quan
Chạy từ trên xuống dưới từ trái qua phải đó bạn.
The sequence of events when a new object is instantiated via the new operator (known as the instantiation process) is as follows:
JVM allocates memory for the instance in the help.
JVM initializes the instance variables to their assigned values or default values.
JVM invokes the constructor.
The first statement of the constructor is always a call to its immediate superclass’ constructor. JVM invokes the selected superclass’ constructor.
JVM executes the instance initializers in the order of appearance.
JVM executes the body of the constructor.
The new operator returns a reference to the new object.
For example,:
Ý mình là khi gọi hàm getMn() à bạn