subclass.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Base(object):
def __init__(self):
self.name = "Base"
def echo(self):
self.hello()
print("name = {}".format(self.name))
self._underscore1_func()
self.__underscore2_func()
def hello(self):
print("My class is Base.")
def _underscore1_func(self):
print("Base::_underscore1_func()")
def __underscore2_func(self):
print("Base::__underscore2_func()")
class Deriv(Base):
def __init__(self):
super().__init__()
self.name = "Deriv"
def hello(self):
print("My class is Deriv.")
def _underscore1_func(self):
print("Deriv::_underscore1_func()")
def __underscore2_func2(self):
print("Deriv::__underscore2_func()")
if __name__ == '__main__':
print(">>>> Base object")
a = Base()
a.echo()
print()
print(">>>> Deriv object")
b = Deriv()
b.echo()
>>>> Base object
My class is Base.
name = Base
Base::_underscore1_func()
Base::__underscore2_func()
>>>> Deriv object
My class is Deriv.
name = Deriv
Deriv::_underscore1_func()
Base::__underscore2_func()
Recommended Posts