1

Say there are two interfaces, which have different methods. I am implementing both interfaces in a class and using methods of both the interfaces.

interface A { void show1(); }
interface B { void show(); }

public class test implements A, B{
    @Override
    void show1(){
        System.out.println("show1");
    }

    @Override
    void show(){
        System.out.println("show");
    }
}

Definition of Multiple Inhertiance:

Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and features from more than one parent object or parent class.

Question

Can I say what I did in my program is Multiple Inheritance ? If No, Why ?

Note

I am using Java 7.

Shreyas
  • 380
  • 1
  • 4
  • 15
  • 4
    Java supports multiple inheritance of interface but not of implementation. – Jon Skeet Apr 04 '16 at 06:14
  • "But not of implementation" . . @JonSkeet . . What does this mean ? – Shreyas Apr 04 '16 at 06:17
  • 4
    You might want to read the difference between `extends` and `implements` – Naman Apr 04 '16 at 06:17
  • 4
    Assuming you copied the description from Wikipedia, there are numerous references to Java on the same page, which describe it. See the last few paragraphs of https://en.wikipedia.org/wiki/Multiple_inheritance#Mitigation for example. – Jon Skeet Apr 04 '16 at 06:21
  • 1
    this link should be helpful in clearing the differences http://stackoverflow.com/questions/3556652/how-do-java-interfaces-simulate-multiple-inheritance – Praveen Kumar Apr 04 '16 at 06:24
  • Yeah, I copied it from whatever first result google gave me . :P. Thanks :) This helped. – Shreyas Apr 04 '16 at 06:25
  • @Shreyas , I have tried to explain something to clear this topic. You could check it. – mmuzahid Apr 04 '16 at 07:19
  • @mmuzahid . . what I understand is that using multiple interfaces, I am able to achieve multiple inheritance, though the actual application of interface is different, but still I am achieving multiple inheritance. . I understood this from the Oracle documentation link provided in the answer I have marked as correct .. so here I am not able to understand how it is not multiple inheritance . . – Shreyas Apr 04 '16 at 07:39

4 Answers4

4

I think implementation of multiple interfaces is not multiple inheritance.

Your object may have implementation of multiple interfaces. For example your Car object may have interface like BreakStatus, FuelTank interfaces but it's not defined Car as a sub-type/derived-type of BreakStatus, FuelTank.

Inheritance is: One object extends other object(parent) properties and/or behaviors.

Java object does not support multiple inheritance(extending multiple object) something like class Child extends Parent1, Parent2 {}

N.B. Java interfaces support extending multiple interfaces, e.g. interface I3 extends I1, I2 {}

mmuzahid
  • 2,252
  • 23
  • 42
4

No. Because main purpose of interface is abstraction, which means hide implementation details from outside. So if you implement one or more interfaces, that relationship is a like a relationship and not is a relationship.

Another purpose of using interfaces is loose coupling between classes. (side outcome of abstraction).

See this is a nice example

user2486322
  • 847
  • 3
  • 13
  • 31
2

Yes what you did in your program is multiple inheritance.

The Java programming language supports multiple inheritance of type, which is the ability of a class to implement more than one interface. An object can have multiple types: the type of its own class and the types of all the interfaces that the class implements.

https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html

Praveen Kumar
  • 1,515
  • 1
  • 21
  • 39
0

Yes you are achieving multiple inheritance using multiple interface, where you can inheriting the definition of two different interfaces.

In java, multiple Inheritance is achieved using Multiple interfaces. Methods in an interface are always abstract by default, which doesn’t let them to give their implementation (or method definition ) in interface itself.

Sandeep Kokate
  • 825
  • 4
  • 16