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

Problem Set 3

The document outlines a problem set for a computing and mathematics course at the Institute of Finance Management. It includes tasks on simple inheritance, constructor usage in inheritance, polymorphism, static methods, and the distinction between static and instance members, as well as aggregation and composition. Each task requires the creation of specific classes and methods to demonstrate key programming concepts.

Uploaded by

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

Problem Set 3

The document outlines a problem set for a computing and mathematics course at the Institute of Finance Management. It includes tasks on simple inheritance, constructor usage in inheritance, polymorphism, static methods, and the distinction between static and instance members, as well as aggregation and composition. Each task requires the creation of specific classes and methods to demonstrate key programming concepts.

Uploaded by

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

THE INSTITUTE OF FINANCE MANAGEMENT

FACULTY OF COMPUTING AND MATHEMATICS

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.

4. Static Methods and Fields


Write a class Calculator with a static method add(int a, int b) that returns the sum of two
integers. Demonstrate how to call this method without creating an object of the class.

5. Static vs Instance Members


Create a class Counter with a static field count and an instance field id. Increment count in
the constructor. Write a program to demonstrate how the static field is shared among all
objects, while the instance field is unique to each object.

6. Aggregation and Composition


Create a class Author with fields name and email. Create another class Book that has a field
author of type Author and another field title. Write a program to demonstrate aggregation
by creating an Author object and associating it with a Book object.

You might also like