WHAT HAPPEN IF WE PRINT AN OBJECT IN JAVA

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java 
 1052  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    What happen if we print an object in java

    A a = new A();
    System.out.println(a);

    It will call the toString() method of that class, if the method is not present in that class, it will look for toSting() method in super class, if its not there, then it will call Object's class toString() method which would give you the memory location (hexadecimal representation) of that object.

      Modified On Sep-22-2015 05:22:26 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!