lly
6
Q:

tostring() java example

public class Test { 

   public static void main(String args[]) {
      Integer x = 5;

      System.out.println(x.toString());  
      System.out.println(Integer.toString(12)); 
   }
}
1
// Java program to illustrate 
// working of toString() method 
class Best_Friend { 
    String name; 
    int age; 
    String college; 
    String course; 
    String address; 
    Best_Friend 
    (String name, int age, String college, String course, String address) 
    { 
        this.name = name; 
        this.age = age; 
        this.college = college; 
        this.course = course; 
        this.address = address; 
    } 
public String toString() 
    { 
        return name + " " + age + " " + college + " " + course + " " + address; 
    } 
public static void main(String[] args) 
    { 
        Best_Friend b =  
        new Best_Friend("Gulpreet Kaur", 21, "BIT MESRA", "M.TECH", "Kiriburu"); 
        System.out.println(b); 
        System.out.println(b.toString()); 
    } 
} 
2
public String toString()
{
      return getClass().getName()+"@"+Integer.toHexString(hashCode());
}
-2

New to Communities?

Join the community