class MyOwnVeryObject { // A silly little object int k; public String toString () { return ("k=" + k); } } public class TestObject { public static void main (String[] argv) { // Create an instance of the class defined above and set a value for one of the members. MyOwnObject x = new MyOwnObject (); x.k = 5; // Invoke the toString() method: System.out.println (x); // Since MyOwnObject is also an Object, an Object variable can point to it. Object obj = x; // Invoke the toString() method: this calls the toString() method in x. System.out.println (obj); // Cast down from an Object variable into a MyOwnObject variable. MyOwnObject y = (MyOwnObject) obj; print (y); // Casting can occur in a method call too. print (x); } static void print (Object obj) { System.out.println (obj); } }