class ObjX { int i; void print () { System.out.println ("i=" + i); } } //end-ObjX public class DynamicExample7 { public static void main (String[] argv) { // Call a method that returns an instance of ObjX. ObjX x = makeAnObject(); // Pass the instance as parameter to a method. printTheObject (x); } // Note: return type is ObjX static ObjX makeAnObject () { ObjX obj = new ObjX (); obj.i = 5; return obj; } // Note: parameter type is ObjX static void printTheObject (ObjX obj) { obj.print(); } }