LoginSignup
0
0

More than 3 years have passed since last update.

抽象クラス

Posted at
import abc


class Car(metaclass=abc.ABCMeta):
    def __init__(self,model=None):
        self.model = model

    @abc.abstractmethod
    def run(self):
        pass


class ToyotaCar(Car):
    def __init__(self, model,enable_auto_run=False):
        super().__init__(model)
        self.enable_auto_run = enable_auto_run

    #継承したクラスでオーバーライドさせないとオブジェクトを生成した時にエラーになる
    def run(self):
        print('fast fun')


toyota_car = ToyotaCar('Lexus')
0
0
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
0
0