0

I created my own class called Property, and instantiated it. Now I am trying to print out one of its instance to the console, but what's been printed out has been this message shown: enter image description here

and this is my code:

package playground;

public class PlayGround{
   public static void main(String[] args) {
      Property a = new Property("house",120.2,1989);
      System.out.println(a);  
   } 
}

package playground;

public class Property {
   private String type;
   private double area;
   private int year;
   public Property(String type, double area, int year){
      this.type=type;
      this.area=area;
      this.year=year;
   } 
}
EMottet
  • 310
  • 1
  • 3
  • 14
D.Danier
  • 21
  • 2

1 Answers1

2

When you use System.out.println() method it calls for the Object's toString() method. Since you didn't override the default toString method of Object class it calls the default toString method of class Object. You can see the Object's toString method from here

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())
uoz
  • 31
  • 1
  • 5
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Kenzo_Gilead Aug 28 '17 at 12:45