【发布时间】:2018-02-18 18:00:15
【问题描述】:
所以本质上,我在两个 concreate 类之间添加了一个抽象类,并且希望这个三明治的底层类能够调用两个父类的所有名称。 这不起作用,我想知道为什么?不是代码,我在没有计算机的情况下只写了逻辑。
调用 get name 后我期望的输出是: 客户!中间人!我的商店!
public abstract class StoreClerk extends Shop {
string name = "MiddleMan!";
public getName {
return this.name + super.getName();
}
}
public class Shop {
string name = "myShop!";
public getName() {
return this.name;
}
}
public class Customer extends StoreClerk {
string name = "customer!";
public getName() {
return this.name + super.getName();
}
}
public class void main(String args[]) {
Customer ibrahim = new Customer();
ibrahim.getName();
}
【问题讨论】:
-
对不起,如果这已经发布了!
-
string在 Java 中不存在 -
@Li357 他写道这是伪代码
-
@payloc 在哪里?致 OP:这种继承没有意义。店员不是商店。商店可以有店员。顾客也不是店员,但商店可以有顾客..
-
@Li357
Not the code, I wrote that without the computer just the logic.猜它代表pseudocode。不过,你是对的,代码在概念上是错误的。另外,易卜拉欣,如果你不是在电脑上做的,你怎么知道它不起作用?
标签: java class inheritance abstract