Java Reference
In-Depth Information
5 .
public double
fractionDone
(
int
targetDay
)
{
double
doubleDay = day;
return
doubleDay/targetDay;
}
6 .
public void
advanceYear
(
int
increase
)
{
year = year + increase;
}
7. The instances of
newMonth
that have their values changed to
6
are indicated in
color as follows:
public void
setDate(
int
newMonth,
int
newDay,
int
newYear)
{
month = monthString(
newMonth
);
day = newDay;
year = newYear;
System.out.println("Date changed to "
+
newMonth
+ " " + newDay + ", " + newYear);
}
The point being emphasized here is that all instances of
newMonth
have their values
changed to 6. Technically speaking, the parameter
newMonth
is a local variable.
So, there is only one local variable named
newMonth
whose value is changed to
6
,
but the net effect, in this case, is the same as replacing all occurrences of
newMonth
with
6
.
8. Yes, it is legal. The point being emphasized here is that the parameter
count
is
a local variable and so can have its value changed, in this case by the decrement
operator.
9. Each case has a
return
statement. A
return
statement always ends the method
invocation, and hence ends the execution of the
switch
statement. So, a
break
statement would be redundant.
10. They are assumed to be instance variables of the calling object.
11.
public int
getDay()
{
return this
.day;
}
public int
getYear()
{
return this
.year;
}