| Author |
Declare and Instantiate an Object in Two Steps
|
mahesh rao
Greenhorn
Joined: Sep 08, 2004
Posts: 18
|
|
I am not sure why the following does not work.
public class Test {
.....
}
class Test2 {
Test t;
t = new Test();
}
But this one works.
public class Test {
....
}
class Test2 {
Test t;
public void setup() {
t = new Test();
}
}
Can anyone explain it. Thanks.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16809
|
|
Java code must be either be in an initializer, in a constructor, in a method, or part of a variable declaration.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: Declare and Instantiate an Object in Two Steps
|
|
|