Extend Multiple Classes Java

Extend Multiple Classes Java

Summary: At the end of this tutorial you will understand the usage of Extend Multiple Classes Java in the code.

We know earlier that Java does not support multiple inheritance but supports partially through interfaces.

After extends there must be only one class of either concrete (non-abstract) or abstract. After implements there must be interfaces only and can be of any number. But if a class would like to extend a number of concrete classes then, how it can? The following program illustrates.

class A {   }
class B extends A {   }
interface C {   }
interface D {   }

public class Demo extends B implements C, D
  public static void main(String args[])
    System.out.println("Hello World");

The above program is a combination of multilevel (between A and B) and multiple (with C and D) inheritance. Demo extends B and in turn B extends A. Now Demo can make use of the methods of A and B. Demo implements the interfaces C and D.

Even though Java does not support multiple inheritance directly, it can achieve all the benefits using extends and implements as in the above program.

2 thoughts on “Extend Multiple Classes Java”

    1. Data binding,data hiding, data abstraction and encapsulation concepts, one results to another. With encapsulation, data abstraction is achieved. Abstraction means hiding the details. For example, you raise the accelerator of a vehicle, the vehicle moves fast. How the accelerator mechanism works is abstracted from you, but still you ride the vehicle. Similarly, one objects’s data is hidden (or to say, abstracted) from another in encapsulation.

Leave a Comment

Your email address will not be published.