1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

多重継承

Last updated at Posted at 2020-08-25

カンマで区切る事で複数継承することができる

qiita.py
class Person(object):
    def talk(self):
        print('talk')

class Car(object):
    def run(self):
        print('run')

class PersonCarRobot(Person,Car):
    def fly(self):
        print('fly')

person_car_robot = PersonCarRobot()
person_car_robot.run()
#run
person_car_robot.talk()
#talk
person_car_robot.fly()
#fly

##同じメソッドが存在する場合
継承する順番で優先度が定まる

qiita.py
class Person(object):
    def talk(self):
        print('talk')

    def run(self):
        print('person_run')

class Car(object):
    def run(self):
        print('run')

class PersonCarRobot(Person,Car):
    def fly(self):
        print('fly')

person_car_robot = PersonCarRobot()
person_car_robot.run()
#peroson_run
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?