Java is a single inheritance language, but in the inheritance relationship of subclasses, there are cases where the parent class and the interface have the same method.
Let's take a step-by-step validation:
1. Subclass inherits the parent class, implements the interface, and the parent class and interface have the same method
Public interface MyInterface {
void Test ();
}
public class Father {public
void Test () {
System.out.println ("Parent class method");
}
public class Son extends Father implements myinterface{}
Subclass directly inherits the parent class and implements the interface without error, which means that the default parent class implements the method
2. We comment out the methods in the parent class and see the results
Public interface MyInterface {
void Test ();
}
public class Father {/
/public void Test () {
// System.out.println ("Parent class method");
// }
}
Obviously, the subclass has an error in the inheritance process and needs to implement the methods in the interface
3. Uncomment the method in the parent class, and the subclass implements the method with the following code:
Public interface MyInterface {
void Test ();
}
public class Father {public
void Test () {
System.out.println ("Parent class method");
}
As you can see, the subclass method hint is the overridden parent class method.
At this point, the verification is complete.