Home>

Where did I write the code for creating the instance and see how it works?
I would appreciate if you could explain it because there was a part that became.

The last line, System.out.println(c);, passed the compile and the result showed [email protected] What does this represent?
Thank you.

code
public class Counter {
   static int count = 0;
  Counter(){
    ++count;
  }
  public static void main(String[] args){
    new Counter();
    Counter c = new Counter();
    c = new Counter();
    c = new Counter();
    System.out.println(c);
  }
}
  • Answer # 1

    What does this represent?

    DefaultObject.toStringThe result of (Oracle).

    The name of the original class of which the object is an instance, the at sign character "@, And an unsigned hexadecimal representation of the hash code for the object.

  • Answer # 2

    Indicates that it is a Counter object.
    Attached to the back@d716361If you want to know who is, please refer to the following articles.

    The story of toString() starting from passing an array to System.out.println