/**
* A utility class containing several overloads of a report method.
*/
public class Reporter {
public static void report(Object obj) {
System.out.println("Object: " + obj);
}
public static void report(Circle circ) {
System.out.println("Circle: " + circ);
}
public static void report(int x, int y) {
System.out.println("Two ints: " + x + " " + y);
}
}
Object
is the root of the class hierarchy.
Every class has Object
as a superclass. All objects,
including arrays, implement the methods of this class.print(String)
and then
println()
.print(String)
and then
println()
.x
- The String
to be printed.Console.charset()
if the Console
exists,
stdout.encoding otherwise.
Console.charset()
if the Console
exists,
stdout.encoding otherwise.
For simple stand-alone Java applications, a typical way to write a line of output data is:
System.out.println(data)
See the println
methods in class PrintStream
.
When an object is printed, Java will implicitly call that object's toString
method. In this code, it is the same as if we had called obj.toString()
here.
The default toString
behaviour for an Object
is not terribly useful---it simply prints the object's class name and memory address.
When an object is printed, Java will implicitly call that object's toString
method. In this code, it is the same as if we had called obj.toString()
here.
The default toString
behaviour for an Object
is not terribly useful---it simply prints the object's class name and memory address.
When an object is printed, Java will implicitly call that object's toString
method. In this code, it is the same as if we had called circ.toString()
here.
When an object is printed, Java will implicitly call that object's toString
method. In this code, it is the same as if we had called circ.toString()
here.