【发布时间】:2015-10-24 09:24:03
【问题描述】:
我在这里使用继承概念。我已将 A 类(超类)扩展为 B 类(子类)。我创建了一个子类的对象,并使用该对象调用了 add() 方法。但它正在打印一个值 5(超类)。 为什么它不采用子类的值 10 ?
class A{
int a=5;
public void add(){
System.out.println(a);
}
}
class B extends A{
int a=10;
}
public class InheritExample {
public static void main(String args[]){
B b1=new B();
b1.add();
}
}
帮助表示赞赏。 谢谢。
【问题讨论】:
标签: java inheritance