【发布时间】:2019-07-09 22:20:47
【问题描述】:
我有三个不同的班级:
1-)
abstract class A {
abstract void one();
void two(){
System.out.println("two");
one();
}
abstract void three();
}
2-)
abstract class B extends A {
void one() {
System.out.println("one");
three();//I think this method has to run
}
void three() {
System.out.println("3");//That
}
}
3-)
public class C extends B {
void three(){
System.out.println("three");
}
}
在 Main 方法中
public static void main(String [] args){
C c=new C();
c.one();
c.two();
c.three();
}
输出:
one
three
two
one
three
three
但我认为在第二个代码中 one() 方法必须运行它的三个方法,它必须显示“3”而不是“三个”,但这段代码在 C 类中运行三个。
【问题讨论】:
标签: java oop inheritance abstract-class