![]() ("color is: " + c4.getColor()) // Print color via getter // You cannot do the following because setRadius() returns void, which cannot be printed ("radius is: " + c4.getRadius()) // Print radius via getter ![]() Modify the TestCircle to test these methods, e.g.,Ĭircle c4 = new Circle() // construct an instance of Circle * The Circle class models a circle with a radius and color. The source codes for Circle.java is as follows: /** Two public methods: getRadius() and getArea(), which return the radius and area of this instance, respectively.Two overloaded constructors - a default constructor with no argument, and a constructor which takes a double argument for radius.Two private instance variables: radius (of the type double) and color (of the type String), with default value of 1.0 and " red", respectively.This first exercise shall lead you through all the basic concepts in OOP.Ī class called circle is designed as shown in the following class diagram. Exercises on Classes An Introduction to Classes and Instances by Example - The Circle Class
0 Comments
Leave a Reply. |