I'm currently reading the book "Big Java Early Objects".
In the section "construction objects in Java" They gave this example below.
import java.awt.Rectangle;
/**
This example demonstrates constructors.
*/
public class ConstructorDemo
{
public static void main(String[] args)
{
// Constructs and prints a rectangle
System.out.println(new Rectangle(5, 10, 20, 30));
// Constructs a rectangle and saves it in a variable
Rectangle box = new Rectangle(5, 10, 20, 30);
System.out.print("box: ");
System.out.println(box);
// The constructor with no arguments
box = new Rectangle();
System.out.print("box: ");
System.out.println(box);
}
}
I think this code should print out a Rectangle. But nothing happens, it only prints out this in the Console:
java.awt.Rectangle[x=5,y=10,width=20,height=30]
box: java.awt.Rectangle[x=5,y=10,width=20,height=30]
box: java.awt.Rectangle[x=0,y=0,width=0,height=0]
Is something wrong with my Eclipse? How can I make this work?
Rectangle#toStringmethod, and that String is being printed in the console.