use of inheritence in python code example
Example 1: inheritance in python 3 example
class Robot:
def __init__(self, name):
self.name = name
def say_hi(self):
print("Hi, I am " + self.name)
class PhysicianRobot(Robot):
def say_hi(self):
print("Everything will be okay! ")
print(self.name + " takes care of you!")
y = PhysicianRobot("James")
y.say_hi()
Example 2: inheritence in python
class A:
def feature1(self):
print('Feature 1 in process...')
def feature2(self):
print('Feature 2 in process...')
class B:
def feature3(self):
print('Feature 3 in process...')
def feature4(self):
print ('Feature 4 in process...')
a1 = A()
a1.feature1()
a1.feature2()
a2 = B()
a2.feature3()
a2.feature4()
class A:
def feature1(self):
print('Feature 1 in process...')
def feature2(self):
print('Feature 2 in process...')
class B(A):
def feature3(self):
print('Feature 3 in process...')
def feature4(self):
print ('Feature 4 in process...')
a1 = A()
a1.feature1()
a1.feature2()
a2 = B()
a2.feature3()
a2.feature4()