budsy remo wrote:
Why do i get "Rectangle@19821f" ?
When you print out the object, System.out.print() will call toString() on the object to get a string that it can print. And since, you didn't implement the toString() method, it will inherit it from the Object class. The toString() method of the Object class generates a string with the class type and the identity hash code, which is what you see.
As Mr. Wong said, you defined a class called Rectangle but did not override the toString() method so when you tried to print the Rectangle instance at line 15, it called the default toString() method as implemented in the Object class, which Rectangle extends. If you override the toString() method, you can display whatever you want.
In the code below, I modified your Rectangle class to implement a toString() method. Note the @Override annotation on line 35. This is not mandatory but tells the compiler the method that follows overrides a method of the base class. If you get the syntax of the method wrong, the compiler will tell you.