Reputation: 2727
Why the Sloop subclass's method get_info doesn't overwrite its superclass' method?
class Boat( object ):
def __init__( self, name, loa ):
"""Create a new Boat( name, loa )"""
self.name= name
self.loa= loa
def get_info(self):
print "Boat:", self.name, "Size:", self.loa
print "This is printed correctly"
class Catboat( Boat ):
def __init__( self, sail_area, * args ):
"""Create a new Catboat( sail_area, name, loa )"""
super(Catboat,self).__init__( * args )
self.main_area= sail_area
def get_info(self):
#print dir(self)
print "Boat:", self.name, "Size:", self.loa, "Sail area:", self.main_area
print "This one also"
class Sloop( Catboat ):
def __init__( self, jib_area, * args ):
"""Create a new Sloop( jib_area, main_area, name, loa )"""
super(Sloop,self).__init__( * args )
self.jib_area= jib_area
def get_info(self):
print "Boat:", self.name, "Size:", self.loa, "Sail area:", self.main_area, "Jib_area:", self.jib_area
print "This should be printed, but it's not"
boat1 = Boat("Titanic", 20)
catboat1 = Catboat(50, "Titanic", 40)
sloop1 = Sloop(70, 60, "Titanic", 50)
boat1.get_info()
catboat1.get_info()
sloop1.get_info()
'''
prints:
Boat: Titanic Size: 20 This is printed correctly Boat: Titanic Size: 40 Sail area: 50 This one also Boat: Titanic Size: 50 Sail area: 60 This one also
Expected:
Boat: Titanic Size: 20 This is printed correctly Boat: Titanic Size: 40 Sail area: 50 This one also Boat: Titanic Size: 50 Sail area: 60 Jib_area: 70 This should be printed, but it's not
"
Upvotes: 0
Views: 90
Reputation: 11070
If the indentation given in the question is right, then the sub classes do not have a get_info() function
Upvotes: 1