1. 对象变量不可以使用“==”判断两变量值是否相等,只是比较两个对象的地址是否相等。
2.因为obj1和obj2两个对象地址是不相等的。
3.第一个输出两个对象的地址不一样,所以是false;第二个输出两个对象里面的值是相等的,所以是true。
4. 这个方法的没有返回值,也不是void类型,而且函数名字与类的名字完全相同。
5. 在Foo类中已经定义了构造方法,以前默认的无参构造函数已经不能再使用,只能自己重新定义无参的构造方法。
6. 执行类成员定义时指定的默认值或类的初始化块,到底执行哪一个要看哪一个“排在前面”。
执行无参构造函数时,要看指定的默认值或类的初始化块哪一个在前面,执行有参构造方法时,就直接输出方法中的值。静态初始化块只执行一次。
创建子类型的对象时,也会导致父类型的静态初始化块的执行。
7.可以在静态方法中,先生成一个对象,用对象.成员访问实例成员。
8.装箱过程是通过调用包装器的valueOf方法实现的,而拆箱过程是通过调用包装器的 intValue方法实现的.
9.integer实现时整型范围为-128到127 第一个未超出范围所以true而第二个超出范围所以false。
10.
1 public class Num {
2 static int count;
3 private int value=100;
4 public Num(){
5 count++;
6 }
7 public Num(int value) {
8 this.value=value;
9 count++;
10 }
11
12 public static void main(String[]args) {
13 Num n1=new Num();
14 Num n2=new Num(100);
15 Num n3=new Num(200);
16 System.out.println("创建的对象数量一共为:"+count);
17 }
18 }