I am creating a object (bb) of Box class.and storing 25 to its attribute value. The object will be created and it will have memory.Now I want to create new instance of Box class but i want it to point it to the same object created for bb and not allocating it new memory again.For example if write Box cc new Box(); and print out cc.value it should print 25.It should not allocate new memory.That is every time we create object it should refer to bb .For example Box newOne = new Box(); and newone.value should give us 25.Is this possible? I don't know if i have described the problem well.I came across this type of question recently in an exam.
Box bb = new Box();
bb.value = 25;
Box cc = new Box();//It should not allocate new memory it should refer to
//the previous memory that we used for bb.
System.out.println(cc.value);//It should give us 25
class Box{
int value;
}