First page Back Continue Last page Overview Graphics

Another Problem

We extend the previous example with a method m() in B:

class A(object):

def m(self):

print("m in A")

class B(A):

def m(self):

A.m(self)

print("m in B")

class C(A):

def m(self):

A.m(self)

print("m in C")

class D(B,C):

pass

d = D()

d.m()

We get the following output:

m in A

m in B

We might expect that D inherits both the methods m() of B and of C, but Python uses only the first class, i.e. B.


Notes:

Wenn die m()-Methoden beispielsweise Daten der Klassen A, B und C speichern, dann würde bei m() von D keine Sicherung der Daten von C erfolgen.