0% found this document useful (0 votes)
3 views

Lecture 7 - Assignment

Uploaded by

Gia Hung
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture 7 - Assignment

Uploaded by

Gia Hung
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Lecture 7 – Polymorphism Assignment

Question 1. Shape Area Calculation:


 Create an abstract Shape class with an abstract method calculateArea().
 Implement subclasses Circle, Square, and Rectangle with specific implementations of
calculateArea().
 Write a main method to create an array of different shapes and calculate their areas.

Question 2. Animal Sound Simulation:


 Create a base class Animal with a method makeSound().
 Create subclasses Dog, Cat, and Cow, each overriding makeSound() to print different
sounds.
 Write a main method that demonstrates polymorphism by storing various animals in an
Animal array and calling makeSound() on each.

Question 3. Payment System:


 Create a base class Payment with a method processPayment().
 Implement subclasses CreditCardPayment, CashPayment, and BankTransferPayment,
each with a custom implementation of processPayment().
 Write a main method where an array of different payment types is processed.

Question 4. Vehicle Speed Comparison


 Define an abstract class Vehicle with an abstract method getSpeed().
 Create subclasses Car and Bicycle, each returning different speed values.
 In the main method, instantiate each type and display their speeds, demonstrating
polymorphism by calling getSpeed() on a list of Vehicle objects.

Question 5. Employee Salary Calculation


 Create an abstract class Employee with an abstract method calculateSalary().
 Create subclasses FullTimeEmployee and PartTimeEmployee, each implementing
calculateSalary() based on different logic.
 Use a main method to create employee objects and display their salaries.

You might also like