Skip to content

Instantly share code, notes, and snippets.

@rdcoder33
Created December 28, 2018 03:24
Show Gist options
  • Save rdcoder33/04c217e865e39262e6db538eaf3e266e to your computer and use it in GitHub Desktop.
Save rdcoder33/04c217e865e39262e6db538eaf3e266e to your computer and use it in GitHub Desktop.
class Robot:
def __init__(self, name, model_no, creator):
self.name = name
self.model_no = model_no
self.creator = creator
def walk(self):
return 'I am walking using my wheels'
def charge(self):
return 'I am charging'
class Dog:
def __init__(self, height, weight, species=None):
self.species = species
self.height = height
self.weight = weight
def speak(self):
return 'Bow Bow'
def walk(self):
return 'I am walking using my legs'
class RoboDog:
def __init__(self, name, model_no, creator, height, weight):
self.robot_obj = Robot(name, model_no, creator)
self.dog_obj = Dog(height, weight)
def work(self):
return 'Serve my Master'
Pika = RoboDog('Pika', 'rd-t1', 'Robo-Labs', '2', '5')
# In multiple inheritance: print(Pika.walk())
# In composition
print(Pika.robot_obj.walk())
print(Pika.dog_obj.speak())
print(Pika.work())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment