Page 106 - CTS - CSA TP - Volume 2
P. 106
COMPUTER SOFTWARE APPLICATION - CITS
Circle myCircle = new Circle(5.0);
// Accessing object properties and methods
System.out.println(“Area of the circle: “ + myCircle.calculateArea());
System.out.println(“Circumference of the circle: “ + myCircle.calculateCircumference());
}
}
Output:
Explanation:
• This program defines a Circle class with a property radius.
• It has a constructor to initialize the radius.
• The calculateArea() method calculates the area of the circle, and the calculateCircumference() method
calculates the circumference.
• In the main() method, an object myCircle of the Circle class is created, and its methods are called to calculate
the area and circumference of the circle.
These examples demonstrate how classes, objects, and methods can be used to model various entities and
perform operations on them in Java. They encapsulate data and behavior within classes, promoting code
organization, reusability, and maintainability.
91
CITS : IT & ITES - Computer Software Application - Exercise 94