Inheritance Program
Inheritance Program
[email protected]
6294360529
**Don’t share the notes with different Section
INHERITANCE QUESTIONS AND ANSWERS
1. Create a parent class Animal with a method speak( ) that prints "Animal speaks." Then,
create a child class Dog that inherits from Animal and includes an additional method bark()
that prints "Dog barks." Demonstrate the inheritance by creating an object of the Dog class
obj and calling both the speak() method from the parent class and the bark() method from
the child class.
2. Define a Father class with a method show_father( ) that prints "This is Father" and a Mother
class with a method show_mother( ) that prints "This is Mother." Then, create a Child class
that inherits from both Father and Mother, and add a method show_child( ) that prints "This
is Child." Use an object of the Child class to call all three methods and display the outputs.
3. Define a Grandparent class with a method show_grandparent( ) that prints "This is
Grandparent." Then, create a Parent class that inherits from Grandparent and has a method
show_parent( ) that prints "This is Parent." Finally, create a Child class that inherits from
Parent and has a method show_child() that prints "This is Child." Use an object of the Child
class to call all three methods and display the outputs.
4. Define a Parent class with a method greet( ) that prints "Hello from Parent." Then, create a
Child class that inherits from Parent and overrides the greet( ) method to print "Hello from
Child." Use an object of the Child class to call the greet( ) method.
5. Define a Parent class with a method greet( ) that prints "Hello from Parent." Then, create a Child
class that inherits from Parent and overrides the greet( ) method to first call the greet() method from
the Parent class using super(), followed by printing "Hello from Child." Use an object of the Child
class to call the greet( ) method and display the output.