Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Challenge 2: Implement an Animal Class

Sumit Rawal answered on May 17, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Solution Review 2: Implement an Animal Class

  • Challenge 2: Implement an Animal Class

    0

    The code below has:

    A parent class named Animal.

    Inside it, define:

    name

    sound

    __init__()

    Animal_details() function

    It prints the name and sound of the Animal.

    Then there are two derived classes*

    Dog class

    Has a property family

    Has an initializer that calls the parent class initializer in it through super()

    Has an overridden method named Animal_details() which prints detail of the dog.

    Sheep class

    Has a property color

    Has an initializer that calls the parent class initializer in it through super()

    Has an overridden method named Animal_details(), which prints detail of the sheep

    The derived classes should override the Animal_details() method defined in the Animal class.

    The overridden method in Dog class should print the value of family as well as the name and sound.

    The overridden method in Sheep class should print the value of color as well as the name and sound

    Input

    name of Dog is set to Pongo, sound is set to Woof Woof, and family is set to Carnivore in the initializer of Dog object.

    name of Sheep is set to Billy, sound is set to Baaa Baaa, and color is set to White in the initializer of Sheep object.

    Now, call Animal_details() from their respective objects. 

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Tags: class python
    Link to this answer
    Share Copy Link
    Contributed on May 17 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.