Created
February 12, 2017 14:07
-
-
Save zeraf29/90c846c733a91ba56a7a790563a27e34 to your computer and use it in GitHub Desktop.
python class override exmapl2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car(): | |
def exclaim(self): | |
print("I'm a Car!") | |
class Yugo(Car): #상속 받을 부모 클래스의 명칭을 ()에 기입 | |
pass | |
class Yugo2(Car): | |
def exclaim(self): #부모클래스 Car의 exclaim 메서드를 오버라이드 | |
print("I'm a Yugo2!") | |
aCar = Car() | |
bCar = Yugo() | |
cCar = Yugo2() | |
aCar.exclaim() | |
bCar.exclaim() #부모 클래스 Car() 의 exclaim 메서드를 상속받아 사용 가능 | |
cCar.exclaim() #부모 클래스로부터 받은 exclaim을 메서드 오버라이드 하여 사용 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment