Java小代码

1.

public class test1 {public static void main(String[] args) {

Person P = new Person("gdsgds");
System.out.println(P.name);//输出为null
}
}
class Person{
String
name;
int age;
public Person(){

}
public Person(String name){

}
}

2.class SDText{

  static SDText sd =new SDText();            加载静态区   第一句    第二句    第三句

  static int x=3;          sd         null          0x001    0x001       0x001

  static int y;            x            0    1     3    3

  public SDText(){         y            0    1    1    1

    x++;

    y++;

}

}//输出x=3  y=1

3.

class SDText{

 

  SDText sd =new SDText();    

 

  int x=3;       

 

  int y;         

 

  public SDText(){      

 

    x++;

 

    y++;

 

}//StackOverflowError

 

posted on 2019-04-08 21:16  Ouchzzzzz  阅读(147)  评论(0)    收藏  举报

导航