day09-继承父类并实现多个接口
This commit is contained in:
13
day10/src/com/inmind/extends_interface06/Demo06.java
Normal file
13
day10/src/com/inmind/extends_interface06/Demo06.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.inmind.extends_interface06;
|
||||||
|
/*
|
||||||
|
继承父类并实现多个接口
|
||||||
|
注意事项:
|
||||||
|
1.非抽象的子类实现类必须重写所有的抽象方法
|
||||||
|
2.如果有抽象方法没有实现,那么子类实现类必须是抽象类
|
||||||
|
3.如果多个接口中有相同的抽象方法,那么子类实现类只要实现一次即可。
|
||||||
|
4.如果多个接口和抽象父类中有相同的抽象方法,那么子类实现类也只要实现一次即可。
|
||||||
|
5.如果多个接口有相同的抽象方法,并且在父类中有一个同名的普通方法,
|
||||||
|
那么子类实现类可以不重写接口中的抽象方法,也可以根据需求来重写,类的方法优先于接口
|
||||||
|
*/
|
||||||
|
public class Demo06 {
|
||||||
|
}
|
||||||
10
day10/src/com/inmind/extends_interface06/Fu.java
Normal file
10
day10/src/com/inmind/extends_interface06/Fu.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package com.inmind.extends_interface06;
|
||||||
|
|
||||||
|
public abstract class Fu {
|
||||||
|
public abstract void methodFu();
|
||||||
|
public abstract void method();
|
||||||
|
|
||||||
|
public void sameMethod(){
|
||||||
|
System.out.println("父类的sameMethod方法");
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.inmind.extends_interface06;
|
||||||
|
|
||||||
|
public interface MyInterface1 {
|
||||||
|
void method1();
|
||||||
|
void method();
|
||||||
|
|
||||||
|
void sameMethod();
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.inmind.extends_interface06;
|
||||||
|
|
||||||
|
public interface MyInterface2 {
|
||||||
|
void method2();
|
||||||
|
void method();
|
||||||
|
|
||||||
|
void sameMethod();
|
||||||
|
}
|
||||||
29
day10/src/com/inmind/extends_interface06/Zi.java
Normal file
29
day10/src/com/inmind/extends_interface06/Zi.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package com.inmind.extends_interface06;
|
||||||
|
|
||||||
|
public class Zi extends Fu implements MyInterface1,MyInterface2{
|
||||||
|
@Override
|
||||||
|
public void methodFu() {
|
||||||
|
System.out.println("重写实现了父类的抽象方法methodFu");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void method1() {
|
||||||
|
System.out.println("重写实现了接口1的抽象方法method1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void method() {
|
||||||
|
System.out.println("重写实现了接口1和接口2的同名的抽象方法method");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void method2() {
|
||||||
|
System.out.println("重写实现了接口2的抽象方法method2");
|
||||||
|
}
|
||||||
|
|
||||||
|
//重写了父类的sameMethod方法
|
||||||
|
@Override
|
||||||
|
public void sameMethod() {
|
||||||
|
super.sameMethod();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user