Java – the same method in the interface and abstract classes
•
Java
I came to the situation:
public interface Intr { public void m1(); } public abstract class Abs { public void m1() { System.out.println("Abs.m1()"); } // public abstract void m1(); } public class A extends Abs implements Intr { @Override public void m1() { // which method am I overriding,well it is Abs.m1() but why? // if method implemented is Abs.m1(),then why I am not getting error for Intr.m1() not implemented. } }
Solution
You meet two conditions at a time; Namely An implementation satisfies both abstract class requirements and interface requirements
As a comment, you do not need an intr unless you use it in another inheritance chain In addition, it may make sense to move the implementation intr to the abstract class definition
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
二维码