How do I implement the Subclass B for the function getdata()
to return the details in the constructor? I could achieve that if the constructor in B
takes a single object, but having difficulty if the objects were two or more and passed as a list
.
This example shows what I intended. Code lacks the full implementation.
class A(object):
def __init__(self, a):
self.a = a
def geta(self):
return str(self.a)
class B(A):
def __init__(self, b,c, [objA1, objA2]):
self.b = b
self.c = c
super().__init__()
# ...
def geta(self):
return str(self.a)
def getb(self):
return str(self.b)
def getdata(self):
return str(self.geta()) + str(self.getb()) + ...
obja1 = A('John')
obja2 = A('Doe')
obj = B('123', '456', [obja1, obja2])
# Test1 obj.getdata() == "John Doe 123 456"