LoginSignup
17
11

More than 5 years have passed since last update.

クラスを継承してオーバーライドするぞ

Posted at

基本だけど継承したときのオーバライドの確認

#! /usr/local/bin/python
# -*- coding:utf-8 -*-


class Parent(object):
    def show(self):
        self.stdout()

    def stdout(self):
        print "poko"


class Child(Parent):
    def stdout(self):
        """
        オーバーライド
        """
        print "child poko"


if __name__ == "__main__":
    parent = Parent()
    parent.show()
    child = Child()
    child.show()
$ python parent_child.py
poko
child poko
17
11
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
17
11