Q:

Write a python code that explains the inheritance?

0

Write a python code that explains the inheritance?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

# 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
Pooja Yes

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now