class A{
public int i=1;
A(){
System.out.println ("A is created and i="+i);
}
}
class B extends A{
B(){
System.out.println ("B is created and i="+i);
}
void printI(){
i++;
System.out.println ("i="+this.i+" "+super.i);
}
}
新建一个B的对象,然后调用printI()
输出结果
Java code
?
1
2
3
A is created and i=1
B is created and i=1
i=2 2
|
|