Questions tagged [multiple-inheritance]

A feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass or base class.

Languages that support multiple inheritance include:

  • C++
  • Common Lisp (via CLOS)
  • Curl
  • Dylan
  • Eiffel
  • EuLisp (via The EuLisp Object System TELOS)
  • Logtalk
  • Object REXX
  • OCaml
  • Perl
  • Perl 6
  • Python
  • Scala (via the use of mixin classes)
  • Tcl (via Incremental Tcl)

Other object-oriented languages, such as Java and Ruby implement single inheritance, although protocols or "interfaces" provide some of the functionality of true multiple inheritance.

2710 questions
101
votes
4 answers

python multiple inheritance passing arguments to constructors using super

Consider the following snippet of python code class A(object): def __init__(self, a): self.a = a class B(A): def __init__(self, a, b): super(B, self).__init__(a) self.b = b class C(A): def __init__(self, a, c): …
Lin
  • 1,547
  • 2
  • 12
  • 26
92
votes
7 answers

Java - Method name collision in interface implementation

If I have two interfaces , both quite different in their purposes , but with same method signature , how do I make a class implement both without being forced to write a single method that serves for the both the interfaces and writing some…
Bhaskar
  • 7,443
  • 5
  • 39
  • 51
91
votes
3 answers

Objective-C multiple inheritance

I have 2 classes one includes methodA and the other include methodB. So in a new class I need to override the methods methodA and methodB. So how do I achieve multiple inheritance in objective C? I am little bit confused with the syntax.
Dilshan
  • 3,231
  • 4
  • 39
  • 50
87
votes
6 answers

Resolving metaclass conflicts

I need to create a class that uses a different base class depending on some condition. With some classes I get the infamous: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all…
Yves Dorfsman
  • 2,684
  • 3
  • 20
  • 28
86
votes
8 answers

Are defaults in JDK 8 a form of multiple inheritance in Java?

A new feature coming in JDK 8 allows you to add to an existing interface while preserving binary compatibility. The syntax is like public interface SomeInterface() { void existingInterface(); void newInterface() default…
Pyrolistical
  • 27,624
  • 21
  • 81
  • 106
84
votes
1 answer

PHP : 'use' inside of the class definition

Recently I came across a class that uses use statement inside of the class definition. Could someone explain what exactly does it do - as I can't find any information about it. I understand that it might be a way of moving it away form a global…
Sebastian Sulinski
  • 5,815
  • 7
  • 39
  • 61
83
votes
11 answers

Why to use Interfaces, Multiple Inheritance vs Interfaces, Benefits of Interfaces?

I still have some confusion about this thing. What I have found till now is (Similar questions have already been asked here but I was having some other points.) Interface is collection of ONLY abstract methods and final fields. There is no…
gprathour
  • 14,813
  • 5
  • 66
  • 90
81
votes
8 answers

Can a normal Class implement multiple interfaces?

I know that multiple inheritances between Interfaces is possible, e.g.: public interface C extends A,B {...} //Where A, B and C are Interfaces But is it possible to have a regular Class inherit from multiple Interfaces like this: public class A…
Joshua
  • 999
  • 1
  • 6
  • 8
80
votes
13 answers

Can one class extend two classes?

My class should extend two classes at the same time: public class Preferences extends AbstractBillingActivity { public class Preferences extends PreferenceActivity { How to do so? Upd. Since this is not possible, how should I use that…
LA_
  • 19,823
  • 58
  • 172
  • 308
78
votes
9 answers

Inheritance from multiple interfaces with the same method name

If we have a class that inherits from multiple interfaces, and the interfaces have methods with the same name, how can we implement these methods in my class? How can we specify which method of which interface is implemented?
masoud ramezani
  • 22,228
  • 29
  • 98
  • 151
77
votes
22 answers

How do Java Interfaces simulate multiple inheritance?

I am reading "The Java Tutorial" (for the 2nd time). I just got through the section on Interfaces (again), but still do not understand how Java Interfaces simulate multiple inheritance. Is there a clearer explanation than what is in the book?
jacknad
  • 13,483
  • 40
  • 124
  • 194
72
votes
4 answers

Are Mixin class __init__ functions not automatically called?

I'd like to use a Mixin to always add some init functionality to my child classes which each inherit from different API base classes. Specifically, I'd like to make multiple different child classes that inherit from one of these different…
B Robster
  • 40,605
  • 21
  • 89
  • 122
72
votes
6 answers

Pointer values are different but they compare equal. Why?

A short example outputs a weird result! #include using namespace std; struct A { int a; }; struct B { int b; }; struct C : A, B { int c; }; int main() { C* c = new C; B* b = c; cout << "The address of b is 0x" <<…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
70
votes
1 answer

Multiple inheritance in python3 with different signatures

I have three classes: A, B and C. C inherits from A and B (in this order). The constructor signatures of A and B are different. How can I call the __init__ methods of both parent classes? My endeavour in code: class A(object): def __init__(self,…
Nikolai Tschacher
  • 1,639
  • 2
  • 17
  • 24
69
votes
9 answers

How can I avoid the Diamond of Death when using multiple inheritance?

http://en.wikipedia.org/wiki/Diamond_problem I know what it means, but what steps can I take to avoid it?
ilitirit
  • 16,016
  • 18
  • 72
  • 111