Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

For this week's discussion, please write a runnable example code showing inheritance and explain your code. Example (For reference, doesn't have to be similar.) CODE class Dog: def __init__(self,...

1 answer below »
For this week's discussion, please write a runnable example code showing inheritance and explain your code.
Example (For reference, doesn't have to be similar.)
CODE
class Dog:
  def __init__(self, first_name, fav_place="Doggy Park"):
    self.first_name = first_name
    self.fav_place = fav_place
  
  def bark(self):
    print("WOOF WOOF!!!")
class Puppy(Dog):
  def __init__(self, first_name, fav_place="Living Room", fav_food="puppy snack"):
    self.first_name = first_name
    self.fav_place = fav_place
    self.fav_food = fav_food
    
  def bark(self):
    print("woof woof")
spot = Puppy("Spot")
print(spot.first_name + " says ", end="")
spot.bark()
champ = Dog("Champ")
print(champ.first_name + " says ", end="")
champ.bark()
OUTPUT
Spot says woof woof
Champ says WOOF WOOF!!!
EXPLANATION
Dog is the parent class and Puppy is the child class. The parent class is passed as a parameter into the child class.
Puppy class is ove
iding bark method from the parent class to have smaller barks. 
spot is our Puppy object. champ is our Dog object.
When printed, spot barks with lower cases and champ barks with all caps.
How will this be graded?
If you submitted something before the due date: +2
If you included the runnable example code: +4
If you included an explanation of what's happening in your code: +2
If you commented on 2 other student's posting: +2
Out of a total of 10 points.
Answered Same Day Jul 02, 2021

Solution

Pratap answered on Jul 02 2021
162 Votes
"""
Program to explain Class Inheritance
"""
class Father:
"""
Father is a parent class
"""
# create a constructor for Father class
def __init__(self):
self.hair_color = "Black"
self.eye_color = "Green"
self.disabled = True
# define a method
def display(self):
print("He has", self.hair_color, "hair color and", self.eye_color, "eye color.",
"Unfortunately he is disabled.")
class Mother:
"""
Mother is also a parent class
"""
# create a constructor for Mother class
def __init__(self):
self.hair_color = "Brown"
self.eye_color = "Blue"
self.disabled = False
# define a...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here