这可能是一个愚蠢的问题,但如果你在一个类的构造函数中使用一个新对象,或者你是否在类体中有对象/变量的相反,那么它是否重要?
public class MyFrame extends JFrame {
private JButton button1;
private JButton button2;
public MyFrame(){
button1 = new JButton("Button1");
button2 = new JButton("Button2");
}
}
Run Code Online (Sandbox Code Playgroud)
与
public class MyFrame extends JFrame {
private JButton button1 = new JButton("Button1");
private JButton button2 = new JButton("Button2");
public MyFrame(){
}
}
Run Code Online (Sandbox Code Playgroud)