Skip to content

Instantly share code, notes, and snippets.

@JoMingyu
Last active March 30, 2018 00:56
class Animal:
def __init__(self, name):
self.name = name
def run(self):
print('{} is running'.format(self.name))
class Cat(Animal):
# ClassName(상위클래스)
def __init__(self, name):
super(Cat, self).__init__(name)
# 상위 클래스의 메소드 호출
# super(현재 클래스, self).method()
def run(self):
print('Cat {} is running'.format(self.name))
def cry(self):
print('Cat {} is crying'.format(self.name))
class Rabbit(Animal):
def __init__(self, name):
super(Rabbit, self).__init__(name)
cat = Cat('catty')
rabbit = Rabbit('carrot')
cat.run()
# Cat catty is running
cat.cry()
# Cat catty is crying
rabbit.run()
# carrot is running
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment