在类中创建对象t1为什么要在方法里面创建
public class Test01 {
public static void main(String[] args) {
}
}
class T1{
}
class T2{
T1 t1=null;
//如果单独在这里创建 t1=new T1();就会报错
public void test(){
t1=new T1();//为什么T1创建对象只能在方法里面
}
}
...全文
2467打赏收藏
在类中创建对象为什么要在方法里面创建
在类中创建对象t1为什么要在方法里面创建 public class Test01 { public static void main(String[] args) { } } class T1{ } class T2{ T1 t1=null; //如果单独在这里创建 t1=new T1();就会报错 public void test(){ t1=new T1();//为什么T1创建对象只能在方法里面 } }