class GrandParent():
def __init__(self, a, b):
self._a = a
self._b = b
def blah(self):
return "GP:" + self._a + self._b
class Parent2(GrandParent):
def __init__(self, a, b, c):
self._a = b
self._b = a
self._c = self.blah()
class Child2(Parent2):
def __init__(self, a, b, c, d):
Parent2.__init__(self, a, b, c)
def blah(self):
return ("C2: " + self._a + self._b
+ self._c + self._d)
c2 = Child2("A", "B", "C", "D")
Here is the code I am supposed to trace. I create an object c2 of Child2. I go in Child2.__init__. I go in Parent2.__init__. I initialize self._a, self._b.
My problem is with self._c.
Parent2 does not have a blah() method, so I would expect it to get self._c from GrandParent.blah(), but instead it goes to the Child2.blah(). Why does this occur?
Child2needs to be a subclass ofParent2(it currently saysParent1). The edit is too small for me to fix it.