[python] 다중상속

덴장·2024년 7월 19일

python

목록 보기
23/30

class Unit:
def init(self): #python의 생성자 init
print("Unit 생성자")

class Flyable:
def init(self):
print("Flyable 생성자")

class FlyableUnit(Unit, Flyable):
def init(self):
#super().init()
'''
다중상속인 경우 모든 클래스의 생성자가 필요하다면
super().init()를 사용하지 말고 클래스별로 init을 호출한다.
'''
Unit.init(self)
Flyable.init(self)

#객체생성
'''
다중 상속인 경우 생성자는 나열된 순서의 첫번째 것으로 생성된다.
class FlyableUnit(Unit, Flyable): 이므로 Unit 의 init가 호출됨.
class FlyableUnit(Flyable,Unit): 였다면 Flyable 의 init가 호출됨
'''
dropship = FlyableUnit()

profile
개발자

0개의 댓글