CodesJava

Easy learning with example program codes

how to implement multiple inheritance in java?


We can implement multiple inheritance in java by following ways:

  • A class can implements multiple interfaces.
  • An interface can extends multiple interfaces.

Example

/**
 * This program is used to show multiple inheritance example.
 * @author CodesJava
 */
interface ShowAge{
          //This method is used to print age.
          void age(int age);
}
 
interface ShowName{
          //This method is used to print name.
          void name(String name);
}
 
public class InterfaceExample2 implements ShowAge, ShowName{
                /**
                 * This method is used to print age.
                 * @author CodesJava
                 */
                @Override
                public void age(int age) {
                        System.out.println("Age = " + age);
                }
 
                /**
                 * This method is used to print name.
                 * @author CodesJava
                 */
                @Override
                public void name(String name) {
                       System.out.println("Name = " + name); 
                }                               
 
                public static void main(String args[]){
                        //object creation
                        InterfaceExample2 obj = new InterfaceExample2();
 
                        //method call
                        obj.name("jai");
                        obj.age(26);
                }
}

Output

Name = jai
Age = 26

Java nterview questions on inheritance

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki