初学者的菜鸟问题。。呵呵。。
class ClassOne{
private char var = 'a ';
char getVar(){return var;}
}
public class Beetle extends ClassOne {
private char var = 'b ';
public static void main(String[] args) {
char a = new ClassOne().getVar();
System.out.println(a);
char b = new Beetle().getVar();
System.out.println(b);
}
}
输出为什么是a a 而不是a b啊??
------解决方案--------------------class Beetle其实继承了private char var = 'a ';只不过由于Beetle类中有private char var = 'b ';它被隐藏了.