Problem Set 3
Problem Set 3
Problem Set 3
1. Simple Inheritance
Create a base class Animal with a method makeSound() that prints “Some generic sound”.
Extend the class with Dog and override makeSound() to print “Bark”. Write a main method
to demonstrate method overriding.
2. Constructor in Inheritance
Create a base class Employee with a parameterized constructor to initialize name and
salary. Extend it with a Manager class that adds an additional field department.
Demonstrate how constructors are called in inheritance.
3. Polymorphism in Action
Create an interface Shape with a method calculateArea(). Implement this interface in two
classes: Circle and Rectangle. Write a program to demonstrate polymorphism by calling
calculateArea() on an array of Shape objects.