class
Test {
//This is where class fields are defined
Test t = new Test(); //Why is this not OK?
//This is where the constructors are defined
Test() {
Test t0 = new Test(); //OK
}
//This is where the methods are defined
void show(){
Test t1 = new Test(); //OK
}
public static void main(
String args[]){
Test t2 = new Test(); //OK
}
}
I am still having hard time understanding why I can CREATE an OBJECT of THE CLASS ITSELF that is still BEING defined?
There is an analogy in Peter Van Der Linden's book that a class is like a RUBBER STAMP. If this analogy is taken literally, then creating an object of the class that is still being defined is like using the rubber stamp while it is still being carved (you will get different inprints of the rubber stamp at different time).
I know a analogy is only a tool for understanding, but in this case it gave me the wrong impression that a class definition has to be complete before an object of it can be created, which naturally leads to the wrong conclusion that a class can ONLY create objects of ANOTHER class but not of ITSELF.
Thanks
EC
[This message has been edited by Esenih Camai (edited January 09, 2001).]