AlgoViz

Multiple inheritance

hard 50 min

A class with several parent classes gets the types, the methods and the fields of all of them.

Watch lesson4:37

Implementation

Parents that get along.

The point: cooperation is written in the parents, before anybody joins them.

The working student

Person owns what both sides share.

class Person:    def __init__(self, *, name: str, **rest) -> None:        super().__init__(**rest)          # object: refuses leftovers        self.name = name    def eat(self) -> str:        return f"{self.name} is eating"    def describe(self) -> list[str]:        return [self.name]

Line 2

The star makes the arguments keyword only. With positions, each class would have to know how many arguments its unknown neighbour wants.

1 of 4

Why it is built this way

  • Java has one parent class, so Person takes that slot.
  • C++ prints a line to prove that the person is made once.