Skip to main content
CMP175
Unit 4 of 8
6 Hours

Inheritance and Polymorphism

6 topics11 videos8 assignments
4.1

Inheritance and Reuse

LecturePractical1 assignment

Assignment

Create a Parent-Child Inheritance Hierarchy

Assignment BriefDue: Complete before Topic 4.2 (Types of Inheritance)

Create a Parent-Child Inheritance Hierarchy

Design a Vehicle parent class with properties (brand, model, year) and methods (displayInfo()). Create two child classes: Car and Bike. Car should add numberOfDoors property, and Bike should add engineType property. Write a program that creates objects of both child classes and calls their methods.

4.2

Types of Inheritance

LecturePractical1 assignment

Assignment

Implement Different Types of Inheritance

Assignment BriefDue: Complete before Topic 4.3 (Polymorphism)

Implement Different Types of Inheritance

Create a program demonstrating single inheritance with an Animal parent class and Dog child class. Then implement multi-level inheritance: Animal → Mammal → Dog. Also demonstrate multiple inheritance (if supported) or use interfaces to simulate it with an Employee class that implements both Payable and Taxable interfaces. Show how each type works with appropriate method overriding.

4.3

Polymorphism

Lecture1 assignment

Assignment

Practice Method Overriding and Polymorphism

Assignment BriefDue: Complete before Topic 4.4 (Abstract Classes)

Practice Method Overriding and Polymorphism

Create a Shape parent class with calculateArea() method. Implement child classes: Circle, Rectangle, and Triangle. Each class should override calculateArea() with their specific formula. Demonstrate how polymorphism allows calling the same method on different object types.

4.4

Abstract Classes

LecturePractical1 assignment

Assignment

Design and Implement an Abstract Class Hierarchy

Assignment BriefDue: Complete before Topic 4.5 (Packages and Interfaces)

Design and Implement an Abstract Class Hierarchy

Create an abstract class Animal with abstract methods makeSound() and move(). The class should also have a concrete method displayInfo() that prints the animal's name. Implement at least three concrete subclasses (e.g., Dog, Cat, Bird) that override the abstract methods. Create objects of each subclass and demonstrate polymorphism by calling methods on them through references of the abstract class type.

4.5

Packages and Interfaces

LecturePractical2 assignments

Assignment 1

Create and Use Packages

Assignment BriefDue: Complete before Topic 4.6 (Lambda Functions)

Create and Use Packages

Create a package structure for a simple project: com.myapp.utils and com.myapp.models. Define a utility class in the utils package with static methods for common operations (e.g., calculate factorial, check if prime). Define a model class (e.g., Student) in the models package. Import and use both classes in a main class located outside these packages, demonstrating proper package naming and access.

Assignment 2

Implement and Use Interfaces

Assignment BriefDue: Complete before Topic 4.6 (Lambda Functions)

Implement and Use Interfaces

Design an interface PaymentProcessor with methods processPayment() and refund(). Implement this interface with two concrete classes: CreditCardProcessor and PayPalProcessor. Each implementation should have different logic. Create a program that accepts payment method as input and processes a payment using the appropriate implementation, demonstrating interface polymorphism.

4.6

Lambda Functions

LecturePractical2 assignments

Assignment 1

Basic Lambda Expressions with Functional Interfaces

Assignment BriefDue: Complete before Unit 5 (Exception Handling)

Basic Lambda Expressions with Functional Interfaces

Create functional interfaces Calculator (add operation). Write lambda expressions to implement that interface.

Assignment 2

Lambda with Collections and Streams

Assignment BriefDue: Complete before Unit 5 (Exception Handling)

Lambda with Collections and Streams

Create a list of integers and use lambda expressions with stream operations to: filter numbers greater than 10.