Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Inheritance.py
- """ script shows all types of inheritance in Python.
- 3 ways that parent and child classes can interact:
- 1.Actions on child imply an action on parent.(Implict Inheritance)
- 2.Actions on child override action on parent. (Override Explicitly)
- 3.Acthons on child alter the action on parent.(Alter Before or After)
- """
- class Parent(object):
- def implicit(self):
- print "PARENT implicit()"
- def override(self):
- print "PARENT override()"
- def altered(self):
- print "PARENT altered()"
- class Child(Parent):
- def override(self):
- print "CHILD override()"
- def altered(self):
- print "CHILD belfore PARENT altered()"
- super(Child,self).altered()
- print "CHILD after PARENT altered()"
- dad = Parent()
- son = Child()
- # Implict Inheritance
- print "Implicit Inheritance Shown"
- dad.implicit()
- son.implicit()
- # Override Explicitly
- print "Override Explicitly Shown"
- dad.override()
- son.override()
- print "Altered Before or After Shown"
- dad.altered()
- son.altered()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement