1.首先是interface (接口可以多继承)
the interface can inherit any number of other interface .
you can have a try to verify the code above
2.接着是 inheritance
what is the output ?
it is :
A
B
Why ?
每个子类构造方法的第一条语句都是隐含的调用super,如果父类没有这种形式的构造函数就会报错.
if the class which is inherited have a constructor with arguments, what will happen ?
interface i1 {}
interface i2{}
interface i3 extends i1,i2 {}
the interface can inherit any number of other interface .
you can have a try to verify the code above
2.接着是 inheritance
class A{
public A (){
System.out.println("A");
}
class B{
public B (){
System.out.println("B");
}
public static void main(String arg[]){
B b = new B();
}
}
what is the output ?
it is :
A
B
Why ?
每个子类构造方法的第一条语句都是隐含的调用super,如果父类没有这种形式的构造函数就会报错.
if the class which is inherited have a constructor with arguments, what will happen ?
Java继承与接口多继承示例解析
本文详细解析了Java中的继承与接口多继承概念,通过实例代码演示了如何实现多个接口,并深入探讨了子类构造方法的调用机制及参数化继承的处理方式。

被折叠的 条评论
为什么被折叠?



