Hey toString() method is used to returns the string representation of your object. It is very easy process to do this. You can use toString() method any where in the program. In the following program I have use PenClass to include all methods.
Code:
public class PenClass {
int x, y;
public PenClass(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
String rets = x+" "+y+"\n";
}
public static void main(String[] args) {
PenClass x = new MyClass(1,2), y = new MyClass(3,4);
System.out.println(x+""+y);
}
}
Bookmarks