0% found this document useful (0 votes)
13 views1 page

Polymorphism Programs

Uploaded by

gangster2003123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Polymorphism Programs

Uploaded by

gangster2003123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Polymorphism Programs

1. Implement a base class Shape with a virtual function area(). Create derived classes
Circle, Rectangle, and Triangle, each overriding the area() function. Use runtime
polymorphism to calculate and display the area of different shapes.

2. Create a base class Animal with a virtual function sound(). Derive classes Dog, Cat, and
Cow, each overriding the sound() function. Use pointers of type Animal to demonstrate
runtime polymorphism by invoking sound() on different animal objects.

3. Create an abstract class Vehicle with a pure virtual function start(). Derive classes Car
and Bike, each implementing the start() method. Use a pointer of type Vehicle to call
start() on objects of Car and Bike.

4. Implement a class hierarchy with a base class Account and derived classes
SavingsAccount and CheckingAccount. Each derived class should have a different
implementation of a withdraw() function. Use dynamic binding to call the appropriate
withdraw() function based on the object type.

You might also like