Java Reference
In-Depth Information
We often use a
println
statement that prints several distinct types, such as:
System.out.println ("Number of students: " + count);
Remember, in this case the plus sign is the string concatenation operator. First,
the value in the variable
count
is converted to a string representation, then the
two strings are concatenated into one longer string, and finally the definition of
println
that accepts a single string is invoked.
Constructors can be overloaded, and often are. By providing multiple versions
of a constructor, we provide multiple ways to set up an object.
SELF-REVIEW QUESTIONS
(see answers in Appendix N)
SR 7.22
How are overloaded methods distinguished from each other?
SR 7.23
For each of the following pairs of method headers, state whether or
not the signatures are distinct. If not, explain why not.
a.
String describe (String name,
int
count)
String describe (
int
count, String name)
b.
void
count ( )
int
count ( )
c.
int
howMany (
int
compareValue)
int
howMany (
int
ceiling)
d.
boolean
greater (
int
value1)
boolean
greater (
int
value1,
int
value2)
SR 7.24
The
Num
class is defined in Section 7.7. Overload the constructor of
that class by defining a second constructor which takes no parameters
and sets the
value
attribute to zero.
The term
testing
can be applied in many ways to software development. Testing
certainly includes its traditional definition: the act of running a completed pro-
gram with various inputs to discover problems. But it also includes any evalua-
tion that is performed by human or machine to assess the quality of the evolving
system. These evaluations should occur long before a single line of code is written.
The goal of testing is to find errors. By finding errors and fixing them, we
improve the quality of our program. It's likely that later on someone else will
find any errors that remain hidden during development. The earlier the errors are
found, the easier and cheaper they are to fix. Taking the time to uncover problems
as early as possible is almost always worth the effort.
Search WWH ::
Custom Search