# A Python program to demonstrate inheritance
# In Python 3.x "class Person" is
# equivalent to "class Person(object)"
class Person(object):
# Constructor
def __init__(self, name):
self.name = name
# To get name
def getName(self):
return self.name
# To check if this person is employee
def isEmployee(self):
return "No"
# Inherited or Sub class (Note Person in bracket)
class Employee(Person):
# Here we return yes
def isEmployee(self):
return "Yes"
# Driver code
emp = Person("Amlendra") # An Object of Person
print(emp.getName(), emp.isEmployee())
emp = Employee("Pooja") # An Object of Employee
print(emp.getName(), emp.isEmployee())
Output:
Amlendra No
need an explanation for this answer? contact us directly to get an explanation for this answerPooja Yes