Inheritance in Java
Various Conflicting Cases
INTRODUCTION :
Inheritance in Java lets a class reuse fields and methods from a parent class, but when multiple interfaces or classes provide methods with the same signature, Java follows clear conflict-resolution rules: class methods always override interface default methods, abstract methods take priority over default methods (forcing the subclass to override), and between interfaces with conflicting defaults the subclass must explicitly choose an implementation. This system allows Java to support multiple inheritance through interfaces without ambiguity.
Below are some of the possible conflicting cases,
CASE 1 : IF A CLASS INHERITS 2 CONCRETE METHODS WITH THE SAME SIGNATURE FROM 2 DIFFERENT CLASSES, IT’S A COMPILE-TIME ERROR.
COMPILATION ERROR : ✅
SOLUTION : NO DIRECT FIX — BECAUSE JAVA DOESN’T ALLOW MULTIPLE INHERITANCE OF CLASSES IN THE FIRST PLACE.
💡 In C++, this is possible and leads to the diamond problem. Java avoids the problem entirely by banning multiple inheritance of classes.
CASE 2 : IF A CLASS INHERITS 2 CONCRETE METHODS WITH THE SAME SIGNATURE FROM 2 DIFFERENT INTERFACES, IT’S A COMPILE-TIME ERROR.
COMPILATION ERROR : ✅
SOLUTION : OVERRIDING — COMPILER FORCES YOU TO OVERRIDE IT IN YOUR CLASS TO RESOLVE THE CONFLICT.
💡If you still want to call one of the interface’s default implementations:
CASE 3 : IF A CLASS INHERITS 2 CONCRETE METHODS WITH SAME SIGNATURE FROM 2 INTERFACES BUT ITS SUPER-CLASS ALREADY HAS AN ABSTRACT METHOD WITH THE SAME SIGNATURE.
COMPILATION ERROR : ✅
SOLUTION : OVERRIDING — COMPILER FORCES YOU TO OVERRIDE AS THE EXTENDING CLASS HAS TO PROVIDE IMPLEMENTATION FOR THE ABSTRACT METHOD OF SUPER-CLASS WHICH IN TURN RESOLVE RESOLVE THE CONFLICT.
💡Java doesn’t complain about the conflict between the two interfaces, because the super-class’s abstract method forces the subclass to override it anyway.
CASE 4 : IF A CLASS INHERITS TWO CONCRETE METHODS WITH THE SAME SIGNATURE FROM 2 INTERFACES BUT ITS SUPER-CLASS ALREADY HAS A CONCRETE METHOD WITH THE SAME SIGNATURE.
COMPILATION ERROR : ❌
REASON : THE COMPILER FOLLOWS THE CLASS OVER INTERFACE RULE. IF A SUPER-CLASS PROVIDES A CONCRETE IMPLEMENTATION, THAT IMPLEMENTATION TAKES PRECEDENCE OVER THE DEFAULT METHODS FROM THE INTERFACES.
💡 If the super-class has a concrete method for that signature, it silently resolves the conflict between the interfaces — no override required.
CASE 5 : IF A CLASS INHERITS TWO CONCRETE METHODS WITH THE SAME SIGNATURE FROM 2 INTERFACES BUT ITS SUPER-INTERFACE ALSO CONTAINS ABSTRACT METHODS WITH THE SAME SIGNATURE.
COMPILATION ERROR : ❌
Get Balajiselvam’s stories in your inbox
Join Medium for free to get updates from this writer.
REASON : THE IMPLEMENTING CLASS MUST STILL OVERRIDE THE METHOD BECAUSE IT’S ABSTRACT IN THE SUPER-INTERFACE WHICH IN TURN RESOLVES THE CONFLICT.
💡Even though I1 and I2 have same default method, I0’s abstract method resolves the ambiguity.
CASE 6 : IF A CLASS INHERITS A METHOD FROM A CLASS AND ALSO FROM AN INTERFACE WITH THE SAME SIGNATURE.
SCENARIOS WITH RESPECT TO RETURN TYPES
CASE 6.1 : COVARIANT RETURN WORKS
CASE 6.2 : COVARIANT RETURN WORKS
CASE 6.3 : SUPER-CLASS + SUPER-INTERFACES CONFLICTS
SCENARIOS WITH RESPECT TO MODIFIERS
CASE 1 : INTERFACE CONFLICTS
CASE 2 : CLASSES ( NO CONFLICTS )
CASE 3 : SUPER-CLASS + SUPER-INTERFACES
SOLUTION TO CASE 3 : OVERRIDE AND MAKE THE ACCESS TO PUBLIC
CASE 4 : SUPER-CLASS + SUPER-INTERFACES
SOLUTION TO CASE 4 : OVERRIDE AND MAKE THE ACCESS TO PUBLIC
Why Compilation Error Shows MyClass Cannot Implements MyInterface Even Though It is not Implementing MyInterface?
REASON FOR THE ERROR :
Compiler is telling you that your class Test (which is trying to implement MyInterface) is getting a method m1() from MyClass, but that method (in MyClass) cannot implement m1() in MyInterface, the reason being “attempting to assign weaker access privileges; was public”. It is not saying that MyClass has an issue. The error message is generated upon compilation of class Test, which means the issue is with Test. It is conveying that the method m1 in MyClass cannot satisfy the requirements of MyInterface (which Test has to fulfill).
SOLUTION :
Override the m1() method in Test Class as public ( More accessibility )








