How to Implement Multiple Inheritance by Using Interfaces in Java? Last Updated : 08 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Multiple Inheritance is a feature of an object-oriented concept, where a class can inherit properties of more than one parent class. The problem occurs when methods with the same signature exist in both the superclasses and subclass. On calling the method, the compiler cannot determine which class method to be called and even on calling which class method gets the priority. Interface is just like a class, which contains only abstract methods. In this article, we will discuss How to Implement Multiple Inheritance by Using Interfaces in Java. Syntax: Class super { --- ---- } class sub1 Extends super { ---- ---- } class sub2 Extend sub1 { ----- ----- }Implementation Multiple inheritances can be achieved through the use of interfaces. Interfaces are similar to classes in that they define a set of methods that can be implemented by classes. Here's how to implement multiple inheritance using interfaces in Java. Step 1: Define the interfaces interface Interface1 { void method1(); } interface Interface2 { void method2(); } Step 2: Implement the interfaces in the class public class MyClass implements Interface1, Interface2 { public void method1() { // implementation of method1 } public void method2() { // implementation of method2 } } Step 3: Create an object of the class and call the interface methods MyClass obj = new MyClass(); obj.method1(); obj.method2(); Example: Java // Declare the interfaces interface Walkable { void walk(); } interface Swimmable { void swim(); } // Implement the interfaces in a class class Duck implements Walkable, Swimmable { public void walk() { System.out.println("Duck is walking."); } public void swim() { System.out.println("Duck is swimming."); } } // Use the class to call the methods from the interfaces class Main { public static void main(String[] args) { Duck duck = new Duck(); duck.walk(); duck.swim(); } } Output: Duck is walking. Duck is swimming. Comment More infoAdvertise with us Next Article Implement Interface using Abstract Class in Java S subramanyasmgm Follow Improve Article Tags : Java java-inheritance java-interfaces Practice Tags : Java Similar Reads How to implement an Interface using an Enum in Java Enumerations serve the purpose of representing a group of named constants in a programming language. For example, the 4 suits in a deck of playing cards may be 4 enumerators named Club, Diamond, Heart, and Spade, belonging to an enumerated type named Suit. We have already discussed the basics of enu 3 min read Interfaces and Inheritance in Java Java supports inheritance and interfaces, which are important concepts for building reusable code. A class can extend another class and can implement one and more than one Java interface. Note: This topic has a major influence on the concept of Java and Multiple Inheritance. Interface Implementation 7 min read Implement Interface using Abstract Class in Java Interface contains only abstract methods that can't be instantiated and it is declared by keyword interface. A class that is declared with the abstract keyword is known as an abstract class in Java. This is a class that usually contains at least one abstract method which can't be instantiated and It 3 min read Difference between Inheritance and Interface in Java Java is one of the most popular and widely used programming languages. Java has been one of the most popular programming languages for many years. Java is Object Oriented. However, it is not considered as a pure object-oriented as it provides support for primitive data types (like int, char, etc). I 3 min read Resolving Conflicts During Multiple Inheritance in Java A class can implement multiple interfaces in java, but what if the implemented multiple default interfaces have default methods with the same signatures? Then in the implementing class, which of the default implementations would be invoked from the several parent interfaces. Java 8 designers have be 5 min read Why Java doesn't support Multiple Inheritance? Multiple Inheritance is a feature provided by OOPS, it helps us to create a class that can inherit the properties from more than one parent. Some of the programming languages like C++ can support multiple inheritance but Java can't support multiple inheritance. This design choice is rooted in variou 5 min read Like