我在Java书中阅读了下面的代码.我明白主类默认继承Thread类,所以currentThread(); 而不是Thread.currentThread(); 也会做这个工作.
但我得不到的是:Thread.currentThread()中的Thread是什么; 或Thread.sleep(); - 类或对象?一个类及其对象可以具有相同的名称吗?
class Demo {
public static void main(String args[]) {
Thread t=Thread.currentThread();
t.setName("My Thread");
System.out.println("Current Thread: "+t);
try {
Thread.sleep(1000);
}
catch(InterruptedException e) {
System.out.println(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)