你好,我对以“(”开头的行感到困惑,我添加了代码。我想知道“(新线程...”和“新线程”)之间的区别是什么。为什么我都给我相同的输出时,我正在做“(新...”)吗?
我不知道我是否正确地描述了我的问题。 谢谢您的回答。
public class HelloRunnable implements Runnable {
public void run() {
System.out.println("Hello from a thread!");
}
public static void main(String args[]) {
System.out.println("main1");
//next 2 lines are doing the same? Both works
(new Thread(new HelloRunnable())).start();
new Thread(new HelloRunnable()).start();
new Dog();
//the next line gives me an failure
// (new Dog());
}}
输出: 主1 线程好! 线程好!