Returning objects

Amethod can return any type of data, including class types that you create. Example as :

class ClassRetObj {
	int x = 200;
	ClassRetObj function1(ClassRetObj t) // return type as ClassRetObj, whose
					     // object is returning
	{
		x = x + 200;
		return t; // return object
	}
}

public class ReturningObjects {
	public static void main(String[] args) {
		ClassRetObj obj1 = new ClassRetObj();
		obj1.x = 500;

		ClassRetObj obj2 = obj1.function1(obj1); // passing Object ob1 as
							// argument
		System.out.println(obj2.x); // calling obj2 value
	}
}