@@ -7,13 +7,39 @@ public static void main(String[] args) {
77 Circle c1 = new Circle ();
88 // Use the dot operator to invoke methods of instance c1.
99 System .out .println ("The circle has radius of "
10- + c1 .getRadius () + " and area of " + c1 .getArea ());
10+ + c1 .getRadius () + " and area of " + c1 .getArea ()
11+ + " and color of " + c1 .getColor ());
1112
1213 // Declare and allocate an instance of class circle called c2
1314 // with the given radius and default color
1415 Circle c2 = new Circle (2.0 );
1516 // Use the dot operator to invoke methods of instance c2.
1617 System .out .println ("The circle has radius of "
17- + c2 .getRadius () + " and area of " + c2 .getArea ());
18+ + c2 .getRadius () + " and area of " + c2 .getArea ()
19+ + " and color of " + c2 .getColor ());
20+
21+ // Declare and allocate an instance of class circle called c2
22+ // with the given radius and default color
23+ Circle c3 = new Circle (2.0 , "blue" );
24+ // Use the dot operator to invoke methods of instance c2.
25+ System .out .println ("The circle has radius of "
26+ + c3 .getRadius () + " and area of " + c3 .getArea ()
27+ + " and color of " + c3 .getColor ());
28+
29+
30+ Circle c4 = new Circle (); // construct an instance of Circle
31+ c4 .setRadius (5.0 ); // change radius
32+ c4 .setColor ("green" ); // change color
33+
34+ System .out .println ("The circle has radius of "
35+ + c4 .getRadius () + " and area of " + c4 .getArea ()
36+ + " and color of " + c4 .getColor ());
37+
38+ Circle c5 = new Circle (5.0 );
39+ System .out .println (c5 .toString ()); // explicit call
40+
41+ Circle c6 = new Circle (1.2 );
42+ System .out .println (c6 ); // println() calls toString() implicitly, same as above
43+ System .out .println ("Operator '+' invokes toString() too: " + c6 ); // '+' invokes toString() too
1844 }
1945}
0 commit comments