Skip to main content

Every class in javaJava has the toString() method in it by default, which is called by System.out.println() if you pass some object of athat class to it. When you try to print object of a class, the System.out.println() method will. By default, this call toString() of the class which returns the className@hashcode of that object.

{ SomeClass sc = new SomeClass(); // Class @ followed by hashcode of object in Hexadecimal System.out.println(sc); } 

You can override the toString method of a class to get different output. See this example

class A { String s = "I am just a object"; @Override public String toString() { return s; } } class B { public static void main(String args[]) { A obj = new A(); System.out.println(obj); } } 

Every class in java has toString() method in it by default, which is called by System.out.println() if you pass some object of a class to it. When you try to print object of a class, the System.out.println() method will call toString() of the class which returns the className@hashcode of that object.

{ SomeClass sc = new SomeClass(); // Class @ followed by hashcode of object in Hexadecimal System.out.println(sc); } 

You can override the toString method of a class to get different output. See this example

class A { String s = "I am just a object"; @Override public String toString() { return s; } } class B { public static void main(String args[]) { A obj = new A(); System.out.println(obj); } } 

Every class in Java has the toString() method in it by default, which is called if you pass some object of that class to System.out.println(). By default, this call returns the className@hashcode of that object.

{ SomeClass sc = new SomeClass(); // Class @ followed by hashcode of object in Hexadecimal System.out.println(sc); } 

You can override the toString method of a class to get different output. See this example

class A { String s = "I am just a object"; @Override public String toString() { return s; } } class B { public static void main(String args[]) { A obj = new A(); System.out.println(obj); } } 
cf...
Source Link
Radiodef
  • 38k
  • 14
  • 95
  • 127

Every class in java has toString() method in it by default, which is called by System.out.println() if you pass some object of a class to it. When you try to print object of a class, the System.out.println() method will call toString() of the class which returns the className@hashcode of that object.

{   SomeClass sc = new SomeClass(); System.out.println(sc); // Class @ followed by hashcode of object in Hexadecimal  Hexadecimal System.out.println(sc); } 

You can override the toString method of a class to get different output. See this example

class A {   String s = "I am just a object";   @Override public String toString()   {   return s;   } } class B {   public static void main(String args[])  {   A obj = new A();   System.out.println(obj);   } } 

Every class in java has toString() method in it by default, which is called by System.out.println() if you pass some object of a class to it. When you try to print object of a class, the System.out.println() method will call toString() of the class which returns the className@hashcode of that object.

{ SomeClass sc = new SomeClass(); System.out.println(sc); //Class @ followed by hashcode of object in Hexadecimal } 

You can override the toString method of a class to get different output. See this example

class A{ String s = "I am just a object"; public String toString() { return s; } } class B{ public static void main(String args[]) { A obj = new A(); System.out.println(obj); } } 

Every class in java has toString() method in it by default, which is called by System.out.println() if you pass some object of a class to it. When you try to print object of a class, the System.out.println() method will call toString() of the class which returns the className@hashcode of that object.

{   SomeClass sc = new SomeClass(); // Class @ followed by hashcode of object in Hexadecimal   System.out.println(sc); } 

You can override the toString method of a class to get different output. See this example

class A {   String s = "I am just a object";   @Override public String toString()   {   return s;   } } class B {   public static void main(String args[])  {   A obj = new A();   System.out.println(obj);   } } 

Every class in java has toString()toString() method in it by default, which is called by System.out.println()System.out.println() if you pass some object of a class to it. When you try to print object of a class, the System.out.println()System.out.println() method will call toString()toString() of the class which returns the className@hashcode of that object.

{ SomeClass sc = new SomeClass(); System.out.println(sc); //Class @ followed by hashcode of object in Hexadecimal } 

You can override the toString method of a class to get different output. See this example

class A{ String s = "I am just a object"; public String toString() { return s; } } class B{ public static void main(String args[]) { A obj = new A(); System.out.println(obj); } } 

Every class in java has toString() method in it by default, which is called by System.out.println() if you pass some object of a class to it. When you try to print object of a class, the System.out.println() method will call toString() of the class which returns the className@hashcode of that object.

{ SomeClass sc = new SomeClass(); System.out.println(sc); //Class @ followed by hashcode of object in Hexadecimal } 

You can override the toString method of a class to get different output. See this example

class A{ String s = "I am just a object"; public String toString() { return s; } } class B{ public static void main(String args[]) { A obj = new A(); System.out.println(obj); } } 

Every class in java has toString() method in it by default, which is called by System.out.println() if you pass some object of a class to it. When you try to print object of a class, the System.out.println() method will call toString() of the class which returns the className@hashcode of that object.

{ SomeClass sc = new SomeClass(); System.out.println(sc); //Class @ followed by hashcode of object in Hexadecimal } 

You can override the toString method of a class to get different output. See this example

class A{ String s = "I am just a object"; public String toString() { return s; } } class B{ public static void main(String args[]) { A obj = new A(); System.out.println(obj); } } 
Source Link
Loading