-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathTestCircle.java
47 lines (38 loc) · 1.74 KB
/
TestCircle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author roberta
*/
public class TestCircle { // save as "TestCircle.java"
public static void main(String[] args) {
// Declare and allocate an instance of class Circle called c1
// with default radius and color
Circle c1 = new Circle();
// Use the dot operator to invoke methods of instance c1.
System.out.println("The circle has radius of "
+ c1.getRadius() + " and area of " + c1.getArea());
// Declare and allocate an instance of class circle called c2
// with the given radius and default color
Circle c2 = new Circle();
// Use the dot operator to invoke methods of instance c2.
System.out.println("The circle has radius of "
+ c2.getRadius() + " and area of " + c2.getArea());
// 3) System.out.println(c1.radius); No, I can't because it has private access in Circle
// c1.radius=5.0;
// 4)
Circle c3 = new Circle(); // construct an instance of Circle
c3.setRadius(5.0); // change radius
c3.setColor("green"); // change color
/**5) toString
Circle c6 = new Circle(5.0);
System.out.println(c1.toString());
Circle c5 = new Circle(1.2);
System.out.println(c5.toString()); // explicit call
System.out.println(c5); // println() calls toString() implicitly, same as above
System.out.println("Operator '+' invokes toString() too: " + c2); // '+' invokes toString() too */
}
}