Error for starting Thread in Main
Hi,
I hope someone could explain the following problem.
class Outer
{
class Innerextends Thread
{
publicvoid run()
{}
}
publicvoid man(String[] args)
{
new Inner().start();
}
}
The above code returned compilation error. I fixed it by moving the
new Inner().start()
into the constructor of Outer class.
Could someone please explain conceptually to me why the code above generated compilation error?
Thank you very much in advance.
regards,
xyoon
[1078 byte] By [
xyoon] at [2007-9-30 5:54:17]

I'm assumiing that your main declaration is just a typo. It should be:
public static void main (String[] args)
But the conceptual problem is with trying to instantiate Inner without an instance of Outer. You can only access an inner class through an instance of the outer class, but you haven't created an instance of the outer class. The correct syntax would be:
new Outer().new Inner().start();
This will first create an instance of Outer and then create an instance of the Inner class and finally invoke the start method of it.