Skip to content

CSE21P8 - Object Oriented Programming - I Lab

Inheritance, Abstraction, Interfaces, and Polymorphism

Term 161

Exp 3. Create a super Class "Box" and subclass "BoxWeight". The subclass "BoxWeight" inherits the superclass. Superclass "Box" consist of three public parameters such as width, height and depth respectively and one method volume to find out volume of boxes. Subclass "BoxWeight" consist of one public parameter weight and one constructor which receives four parameters such as box width, height, depth and weight respectively from user. Create two objects of "BoxWeight" class to find out box volume and Box weight. Now write a Java program using inheritance to solve this problem.

Term 171

Exp 2. Create a super Class "Box" and subclass "Box Weight". The subclass "Box Weight" inherits the superclass. Superclass "Box" consist of three public parameters such as width, height and depth respectively and one method volume to find out volume of boxes. Subclass "BoxWeight" consist of one public parameter weight and one constructor which receives four parameters such as box width, height, depth and weight respectively from user. Create two objects of "BoxWeight" class to find out box volume and Box weight. Now write a Java program using inheritance to solve this problem.

Term 191

Exp 1. Create a super Class "Box" and subclass "BoxWeight". The subclass "BoxWeight" inherits the superclass. Superclass "Box" consist of three public parameters such as width, height and depth respectively and one method volume to find out volume of boxes. Subclass "BoxWeight" consist of one public parameter weight and one constructor which receives four parameters such as box width, height, depth and weight respectively from user. Create two objects of "BoxWeight" class to find out box volume and Box weight. Now write a Java program using inheritance to solve this problem.

Term 211

Exp 01. Write a Java program to create an abstract class named Shape that contains two integers and an empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printArea() that prints the area of the given shape.

Exp 06. Create a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable interfaces. Assume that all eight sides of the octagon are of equal length. The area can be computed using the following formula:

\[ \text{area} = (2 + 4/\sqrt{2}) \times \text{side} \times \text{side} \]

Draw the UML diagram that involves Octagon, GeometricObject, Comparable, and Cloneable. Write a Java program that creates an Octagon object with side value 5 and displays its area and perimeter. Create a new object using the clone method and compare the two objects using the compareTo method.