Skip to main content

Multiple Inheritance using Interface Example in Java

2 min read Updated May 29, 2026
Share:
On this page (10sections)

Introduction

Multiple Inheritance Using Interface is a classic Java console program that demonstrates the concept with complete source code and sample output. These programs cover your first Java class, constructors, methods and simple OOP building blocks.

This tutorial walks through the program line by line, explains how the logic works, and highlights best practices you can apply in your own code.

Definition

Inheritance is when an object or class is based on another object or class, using the same implementation specifying implementation to maintain the same behavior. It is a mechanism for code reuse and to allow independent extensions of the original software via public classes and interfaces. The relationships of objects or classes through inheritance give rise to a hierarchy. Multiple Inheritance allows a class to have more than one super class and to inherit features from all parent class. it is achieved using interface.

Syntax

public interface A{
	//Do Something
}
public interface B extends A{
	//Do Something
}
public interface C extends A{
	//Do Something
}

Multiple Inheritance Using Interface Example Program

interface vehicleone{
	int  speed=90;
	public void distance();
}

interface vehicletwo{
	int distance=100;
	public void speed();
}

class Vehicle  implements vehicleone,vehicletwo{
	public void distance(){
		int  distance=speed*100; 
		System.out.println("distance travelled is "+distance);
	}
	public void speed(){
		int speed=distance/100;
	}
}

class MultipleInheritanceUsingInterface{
	public static void main(String args[]){
		System.out.println("Vehicle");
		obj.distance();
		obj.speed();
	}
}

Sample Output

distance travelled is 9000

When to use

Use this multiple inheritance using interface example when learning or revising core Java syntax.

How it works

  1. Execution begins in the main method — the JVM calls this method when you run the class.

  2. int speed=90; updates a variable used in the calculation or output.

  3. int distance=100; updates a variable used in the calculation or output.

  4. int distance=speed*100; updates a variable used in the calculation or output.

  5. A println / print call writes text to the console — part of the sample output below.

  6. int speed=distance/100; updates a variable used in the calculation or output.

  7. A println / print call writes text to the console — part of the sample output below.

  8. Compare your console output with the sample output for Multiple Inheritance Using Interface to confirm the program behaves correctly.

Best Practices

  • Name classes in PascalCase and follow one public class per file when starting out.
  • Keep main short — delegate work to other methods as programs grow.

Common Mistakes

  • Copying code without understanding each line — practice by changing one statement at a time.
  • Mismatching the public class name and the .java filename.
  • Forgetting semicolons at the end of statements.

Frequently Asked Questions

What does the Multiple Inheritance Using Interface program demonstrate?
It shows how to implement multiple inheritance using interface in Java with a complete runnable example and expected console output.
How do I run this Java program?
Save the code in a `.java` file matching the public class name, compile with `javac`, then run with `java ClassName`.
When would I use this pattern?
Use this pattern whenever you need the same logic in homework, practice or small utility tools.

Related Tutorials

Search tutorials