代码比较长,如下,里面加了注释,赶紧抄上去吧。
interface A {
String a = "this is string A.";
}
interface B extends A {
String b = "this is string B.";
}
interface C extends B {
String c = "this is string C.";
}
class D implements C {
public void display() {
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
class E {
public static void main(String[] args) {
// 显示每个接口中常量字符串来展示接口的继承性
System.out.println(D.a);
System.out.println(D.b);
System.out.println(D.c);
// 创建D的对象, 调用D的方法展示接口的继承性
D d = new D();
d.display();
}
}
public interface A {
public String a = "a";
}
public interface B extends A {
public String b = "b";
}
public interface C extends B {
public String c = "c";
}
public class D implements C {
public void showA() {
System.out.println(a);
}
public void showB() {
System.out.println(b);
}
public void showC() {
System.out.println(c);
}
}
public class E {
public static void main(String args[]) {
D d = new D();
d.showA();
d.showB();
d.showC();
}
}
你能把问题描述得这么清楚应该写得出来吧,学编程别偷懒