Before I even get started trying to figure this out, CodeGym has once again given us code using a structure they haven't taught us yet. I would like to know what is going on before I do anything else:
private static Thread addMoney = new Thread()
{
@Override
public void run()
{
while (!isStopped)
{
account.deposit("1000"); // Make a deposit
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
break;
}
}
}
};
What I don't understand is the use of brackets after Thread(). Usually there would be a semi-colon ending the statement there, and if you need to override the run() method you would create a new class that extends Thread. That's what we've done before. Can someone explain what's going on here?
EDIT: Is the above code functionally the same thing as:
private Thread addMoney = new myThread();
public static class myThread extends Thread
{
@Override
public void run()
{
while (!isStopped)
{
account.deposit("1000"); // Make a deposit
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
break;
}
}
}
}