2013-01-13 | Paul Boddie | file changeset files shortlog | Added a note about ambiguous/multiply-defined classes and functions. |
paul@182 | 1 | #!/usr/bin/env python |
paul@182 | 2 | |
paul@182 | 3 | class A: |
paul@182 | 4 | def a(self): |
paul@246 | 5 | return self.x # x not defined in this class, provided in subclasses |
paul@182 | 6 | |
paul@182 | 7 | class B(A): |
paul@246 | 8 | x = 123 # x provided here |
paul@182 | 9 | |
paul@182 | 10 | class C(A): |
paul@182 | 11 | def __init__(self, x): |
paul@246 | 12 | self.x = x # x provided here |
paul@182 | 13 | |
paul@182 | 14 | b = B() |
paul@182 | 15 | c = C(456) |
paul@182 | 16 | |
paul@182 | 17 | p = b.a() |
paul@182 | 18 | q = c.a() |
paul@182 | 19 | |
paul@246 | 20 | result_123 = p |
paul@246 | 21 | result_456 = q |
paul@246 | 22 | |
paul@182 | 23 | # vim: tabstop=4 expandtab shiftwidth=4 |