Java Reference
In-Depth Information
new
Circle()
SR5.
Figure 3.5. contains a class
Coordinates
. Evaluate the expression shown
below. When executing the constructor call or evaluating the call to function
String
, step over the calls, i.e. do the call as an indivisible action in terms of the
specification of the method.
(
new
Coordinates(5, 6)).toString()
SR6.
Consider these three assignment statements:
Coordinates x=
new
Coordinates(5, 6);
Coordinates y=
new
Coordinates(5, 6);
Coordinates z= y;
What is the value of the expression
x==y
? Of
x==z
? Of
y==z
? Of
x==x
?
Answers to Self-review exercises
SR1.
String s; Employee emp;
SR2.
(1) create a folder of class
C
, (2) execute the constructor call
C(
args
);
,
and (3) yield the name of the new folder as the value.
/**
An instance is a circle with a center and a radius
*/
public class
Circle {
/**
The circle has center
cent
and
radius
rad
*/
public
Coordinates center;
public int
radius;
/**
Constructor: a circle with center
(x, y)
and radius
r */
public
Circle (
int
x,
int
y,
int
r) {
center=
new
Coordinates(x, y);
radius= r;
}
/** =
the center of the circle
*/
public
Coordinates center() {
return
center; }
/** =
the radius of the circle
*/
public int
radius() {
return
radius; }
/** =
the diameter of this circle
*/
public int
diameter() {
return
2*radius; }
/** =
the area of this circle
*/
public double
area() {
return
Math.PI * radius * radius; }
}
Figure 3.6:
Class
Circle
Search WWH ::
Custom Search