Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Wednesday, January 21, 2009

toString() Overriding Program

/**

* CallbyAddress obj = new CallbyAddress(); System.out.println(obj); Above print

* statement should print "Unikaihatsu"

*

*

*/

public class CallbyAddress {

/**

* overrides the toString() of Object class

*/

public String toString() {

return "Unikaihatsu";

}

/**

* displays the this.toString() message on console

*

*/

public static void display() {

System.out.println(new CallbyAddress());

}

/**

* execution begin from here

*

* @param args

* commandline arguments

*/

public static void main(String[] args) {

display();

}

}

No comments:

Post a Comment

Followers