Java uses internal classes to implement multiple inheritance
•
Java
Example 1
public class Father {
public int strong() {
// 强壮指数
return 9;
}
}
public class Mother {
public int kind() {
// 友好指数
return 8;
}
}
public class Son {
// 内部类继承Father类
class Father_1 extends Father {
public int strong() {
return super.strong() + 1;
}
}
class Mother_1 extends Mother {
public int kind() {
return super.kind() - 2;
}
}
public int getStrong() {
return new Father_1().strong();
}
public int getKind() {
return new Mother_1().kind();
}
}
public class Test {
public static void main(String[] args) {
Son son = new Son();
System.out.println("Son 的强壮指数:" + son.getStrong());
System.out.println("Son 的友好指数:" + son.getKind());
}
}
Son 的强壮指数:10 Son 的友好指数:6
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
