Advertisement
Adehumble

Week8|9 Coding Exercise 7

Apr 1st, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #7
  2. #This program demonstrates the idea of class inheritance and how to overwrite instance methods
  3.  
  4.  
  5. class Clothing():
  6.     """This is a superclass"""
  7.    
  8.     def wear(self):
  9.         return "I'm wearing this fashionable piece of clothing!"
  10.    
  11.     def sell(self):
  12.         return "Buy my piece of clothing!"
  13.    
  14. class Socks(Clothing):
  15.     """This is a sub#lass"""
  16.    
  17.     def lose_one(self):
  18.         return "Where did my other one go?"
  19.    
  20.     def wear(self):
  21.         return "Take a look at my socks they are gorgeous!"
  22.        
  23.     def sell(self):
  24.         return "Buy my socks!"
  25.  
  26. #This is an object created from Socks subclass
  27. clean_socks=Socks()
  28.    
  29.  
  30. print(clean_socks.wear())
  31. print("\n",clean_socks.lose_one())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement