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

Labsheet 7

Uploaded by

devmith2005
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)
15 views

Labsheet 7

Uploaded by

devmith2005
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

ICT 1411 Object Oriented Programming

Lab sheet – OOP Concepts


Abstract Class Shape:
• Define an abstract class named Shape with the following attributes and methods:
Instance Variables:
String name - To store the name of the shape.
• Abstract Methods:
double calculateArea() - to calculate the area of the shape. This method should be
abstract.
• Concrete Methods:
void display() - to display the name of the shape and its area. This method should call
calculateArea().

Class Circle:
• Create a class Circle that extends Shape. Include:
Instance Variables:
double radius - to store the radius of the circle.
• Constructor:
A constructor to initialize the name and radius.
• Methods:
Implement the calculateArea() method to return the area of the circle (π * radius
* radius).

Class Rectangle:
• Create a class Rectangle that extends Shape. Include:
Instance Variables:
double length - to store the length of the rectangle.
double width - to store the width of the rectangle.
• Constructor:
A constructor to initialize the name, length, and width.
• Methods:
Implement the calculateArea() method to return the area of the rectangle (length
* width).

Main Class ShapeTest:


• Create a main class ShapeTest to:
Instantiate objects of Circle and Rectangle with appropriate values.
Use polymorphism to store these objects in an array of type Shape.
Loop through the array and call the display() method for each shape.

You might also like