日期:2014-05-20 浏览次数:20631 次
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);
}
}
A is created and i=1
B is created and i=1
i=2 2
public class A {
public int i = 1;
A() {
System.out.println("A is created and i=" + i);
}
public static void main(String[] args) {
B b = new B();
b.printI();
}
}
class B extends A {
int i = 1;
B() {
System.out.println("B is created and i=" + i);
}
void printI() {
i++;
System.out.println("i=" + this.i + " " + super.i);
}
}