模糊的JAVA接口

时间:2012-11-17 00:50:17

标签: error-handling

如何定义类/接口Adult,Student和Engineer,以便下一个序列只在指定的地方给出编译错误?

class Test {
public static void main(String args[]) {
Adult a = new Student(); //without giving compilation error
Adult b = new Engineer();//without giving compilation error
a.explorare(); //without giving compilation error
b.explorare(); //without giving compilation error
a.afisare(); //without giving compilation error
b.afisare(); //compilation error

1 个答案:

答案 0 :(得分:1)

这是不可能的,如果a.afisare()编译那么b.afisare()也是如此。