class_inherit1.py 328 B

123456789101112131415161718192021
  1. class A:
  2. def __init__(self, x):
  3. print('A init', x)
  4. self.x = x
  5. def f(self):
  6. print(self.x, self.y)
  7. class B(A):
  8. def __init__(self, x, y):
  9. A.__init__(self, x)
  10. print('B init', x, y)
  11. self.y = y
  12. def g(self):
  13. print(self.x, self.y)
  14. A(1)
  15. b = B(1, 2)
  16. b.f()
  17. b.g()