Method Overridding in Inherited Class

36 Views Asked by At

When accessing the object created from extended class by using the base class method, it is returning parent attribute values. So the only way to return extended attribute values here is to override the base class method display also?

class Developer:
  def __init__(self):
    self.__seniority = 'Junior'
    self.skills = ''

  def display(self):
    print('Welcome with {seniority} developer with skills {skills}'.format(
            seniority=self.__seniority, skills = self.skills))

class Python(Developer):
  def __init__(self):
    super().__init__()
    self.__seniority = 'Senior'
    self.skills = 'NodeJS'


t1 = Developer()
t2 = Python()
t1.display() -- Welcome with Junior developer with skills
t2.display() -- Welcome with Junior developer with skills NodeJS
0

There are 0 best solutions below