codingpython
Inheritance with encapsulated fields
Given the following class Dog, create an instance of a Poodle and a Lab by creating sub-classes of Dog called Poodle and Lab and creating an instance of each. Each sub-class should implement the bark() and bark_age() method. bark() should print the Dog’s name and bark_age() should print the Dog’s age. The name and age for the Poodle and Lab should be encapsulated within the parent Dog class as fields. The names and ages of the Dogs are specified below. After the classes are implemented and the Dogs are instantiated, call bark() and bark_age() on the Poodle and Lab.
python'''
Poodle
name: Fluffy
age: 3
Lab
name: Buddy
age: 5
'''
class Dog:
def bark(self, func):
...
def bark_age(self, func):
...