public class StudentFormMain {  
    public static void main(String[] args) {
        new StudentForm();
    }
}二级和二级
public class StudentForm extends JFrame {
    public StudentForm(){
        setTitle("Admission Form");
        setSize(300,250);
        setVisible(true);   
    }
}我的问题是
这些陈述之间有什么区别?
StudentForm studentform=new StudentForm();和
new StudentForm()第一条语句声明该类的Obj并调用构造器,但在第二条语句中,只有Constructor正在调用。
注:结果相同
super(""); set the title of the frame因为它正在调用超类构造函数。我们还可以使用setTitle("")方法设置标题
也请区分不同的方法。
发布于 2014-02-07 06:59:46
StudentForm studentform=new StudentForm();
您正在创建一个类型为StudentForm的对象,并将其分配给一个名为studentform的引用(在字段中使用camelCase,即studentForm而不是studentform )。现在,您可以使用studentForm来调用对象的一些方法/访问字段。
eg: studentForm.toString()
如果不能获得对对象的引用,则不能对该对象使用非静态方法。
https://stackoverflow.com/questions/21621096
复制相似问题