
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to Implement Multiple Inheritance
In this article, we will understand how to implement multiple inheritance. Java does not support multiple inheritance. This means that a class cannot extend more than one class, but we can still achieve the result using the keyword 'extends'.
Algorithm
Step 1 – START Step 2 – Declare three classes namely Server, connection and my_test Step 3 – Relate the classes with each other using 'extends' keyword Step-4 – Call the objects of each class from a main function. Step 5 – STOP
Example 1
class Server{ void my_frontend(){ System.out.println("Connection to frontend established successfully");} } class Java extends Server{ void my_backend(){ System.out.println("Connection to backend established successfully"); } } class connection extends Java{ void my_database(){ System.out.println("Connection to database established successfully"); } } public class my_test{ public static void main(String args[]){ connection my_connection=new connection(); my_connection.my_database(); my_connection.my_backend(); my_connection.my_frontend(); } }
Output
Connection to database established successfully Connection to backend established successfully Connection to frontend established successfully
Example 2
interface My_restaurents { void eat(); } interface My_journey { void travel(); } class Holiday implements My_restaurents, My_journey { public void eat() { System.out.println("I am trying this food"); } public void travel() { System.out.println("I am trying this route"); } } public class My_trip { public static void main(String args[]) { Holiday my_schedule = new Holiday(); my_schedule.eat(); my_schedule.travel(); } }
Output
I am trying this food I am trying this route
- Related Articles
- Haskell Program to Implement multiple inheritance
- Java and multiple inheritance
- Multiple inheritance by Interface in Java
- Why multiple inheritance is not supported by Java?
- Why multiple inheritance is not supported in Java
- How multiple inheritance is implemented using interfaces in Java?
- Multiple Inheritance in C++
- Multiple inheritance in JavaScript
- C# and Multiple Inheritance
- Does Python support multiple inheritance?
- Java Program to Implement LinkedList
- Does Java support multiple inheritance? Why? How can we resolve this?
- What is diamond problem in case of multiple inheritance in java?
- Java program to implement bubble sort
- Java program to implement selection sort

Advertisements