Java Reference
In-Depth Information
This is actually just one of several println() methods in the PrintStream
class (we discuss Java I/O and stream classes in chapter 9). The variable
named System.out references an instance of the PrintStream class. You
can take advantage of the other overloaded versions of println() ,which
include:
println () <- prints out just a line separator
println (boolean)
println (char)
println (char[])
println (double)
println (float)
println (int)
println (long)
println (java.lang.Object) - invokes the toString() method
of the object
In general, any change to the type or number of parameters is legal overload-
ing. Note, however, that a change in the return type alone does not produce an
overloaded method. The compiler does not permit the following:
void aMethod (int k) {...}
int aMethod (int k) {...}
because only the return type was changed. Neither does changing the parameter
names produce an overloaded method. For example,
void aMethod (int x, int y, int z) { ... }
void aMethod (int i, int j, int k) { ... }
is not legal. Only the parameter types are examined, not the names.
3.3.4 Constructors
The new operator creates an instance of a class as in
...
int i = 4;
Test test = new Test (i);
...
The statement declares a variable named test of the Test type and creates an
instance of the Test class with the new operator. The argument of new must
correspond to a special method in the class called a constructor.
The constructor looks much like a regular method in that it has an access
modifier and name and holds a list of parameters in parentheses. However, a
Search WWH ::




Custom Search