//问题1:输出是什么?为什么?
class A {
public int i = 10;
}
class B extends A{
public int i = 20;
}
public class TestPolm{
public static void main(String args[]){
B b = new B();
A a = b;
System.out.println(b.i);
System.out.println(a.i);
}
}
Java code
//问题2:输出是什么?为什么?
class A {
private int i = 10;
public void printI(){
System.out.println(i);
}
}
class B extends A{
private int i = 20;
}
public class TestPolm{
public static void main(String args[]){
B b = new B();
A a = b;
b.printI();
a.printI();
}
}
Java code
//问题3:输出是什么?为什么?
class A {
private int i = 10;
public void printI(){
System.out.println(i);
}
}
class B extends A{
private int i = 20;
public void printI(){
System.out.println(i);
}
}
public class TestPolm{
public static void main(String args[]){
B b = new B();
A a = b;
b.printI();
a.printI();
}
}