Posts: 7
Threads: 1
Joined: Feb 2019
class SuperClass:
def __init__(self,a1,a2):
self.attribute1=a1
self.attribute2=a2
def getAttribute1(self):
return self.attritube1
def setAttribute2(self,a1):
self.attritube1=a1
def getAttribute2(self):
return self.attribute2
def setAttribute1(self,a2):
self.attribute2=a2
class SubClass (SuperClass):
def __init__(self,a1,a2,a3):
SuperClass.__init__(self,a1,a2)
def getAttribute3(self):
return self.attribute3
def setAttribute3(self,a3):
self.attribute3=a3
def printMessage(self):
print("My attributes are:", self.getAttribute1() ,self.getAttribute2(), self.getAttribute3())
testObject=SubClass("Hello","World","!!!")
testΟbject.printMessage() yes i correct the underscores and delete testobject. I cant find the problem in Superclass seem ok to me
Posts: 8,160
Threads: 160
Joined: Sep 2016
Feb-20-2019, 12:13 PM
(This post was last modified: Feb-20-2019, 12:14 PM by buran.)
Again, look at the indentation of different methods in both classes. Do you think the indentation of getters and setters in the SuperClass is OK?
by the way, using super() in the SubClass.__init__() method was better, than current one, although current one is also OK.
Posts: 7
Threads: 1
Joined: Feb 2019
class SuperClass:
def __init__(self,a1,a2):
self.attribute1=a1
self.attribute2=a2
def getAttribute1(self):
return self.attritube1
def setAttribute2(self,a1):
self.attritube1=a1
def getAttribute2(self):
return self.attribute2
def setAttribute1(self,a2):
self.attribute2=a2
class SubClass (SuperClass):
def __init__(self,a1,a2,a3):
SuperClass.__init__(self,a1,a2)
def getAttribute3(self):
return self.attribute3
def setAttribute3(self,a3):
self.attribute3=a3
def printMessage(self):
print("My attributes are:", self.getAttribute1() ,self.getAttribute2(), self.getAttribute3())
testObject=SubClass("Hello","World","!!!")
testΟbject.printMessage() I guess i need __ after . but still i cant make it correct
Posts: 8,160
Threads: 160
Joined: Sep 2016
class SuperClass:
def __init__(self,a1,a2):
self.attribute1=a1
self.attribute2=a2
def getAttribute1(self):
return self.attribute1
def setAttribute2(self,a1):
self.attritube1=a1
def getAttribute2(self):
return self.attribute2
def setAttribute1(self,a2):
self.attribute2=a2
class SubClass (SuperClass):
def __init__(self,a1,a2,a3):
SuperClass.__init__(self,a1,a2)
# better
# super().__init__(self,a1,a2)
self.attribute3 = a3
def getAttribute3(self):
return self.attribute3
def setAttribute3(self,a3):
self.attribute3=a3
def printMessage(self):
print("My attributes are:", self.getAttribute1() ,self.getAttribute2(), self.getAttribute3())
testObject=SubClass("Hello","World","!!!")
testObject.printMessage() you may want also to check the other thread - https://python-forum.io/Thread-Class-exa...-the-error
Posts: 3
Threads: 1
Joined: Feb 2019
Feb-20-2019, 12:47 PM
(This post was last modified: Feb-20-2019, 12:51 PM by rajesh1997.)
indentation error in your program . and also function define problem. and function not calling
|