class_inherit_mul.py 632 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # test multiple inheritance of user classes
  2. class A:
  3. def __init__(self, x):
  4. print('A init', x)
  5. self.x = x
  6. def f(self):
  7. print(self.x)
  8. def f2(self):
  9. print(self.x)
  10. class B:
  11. def __init__(self, x):
  12. print('B init', x)
  13. self.x = x
  14. def f(self):
  15. print(self.x)
  16. def f3(self):
  17. print(self.x)
  18. class Sub(A, B):
  19. def __init__(self):
  20. A.__init__(self, 1)
  21. B.__init__(self, 2)
  22. print('Sub init')
  23. def g(self):
  24. print(self.x)
  25. print(issubclass(Sub, A))
  26. print(issubclass(Sub, B))
  27. o = Sub()
  28. print(o.x)
  29. o.f()
  30. o.f2()
  31. o.f3()