爲什麼我可以訪問getName()
方法?我的班級沒有擴展類Thread
只是實現了接口Runnable
。getName()來自類Thread
public class MyThread implements Runnable {
public void run() {
System.out.println("MyThread is running");
}
public static void main(String[] args){
MyThread thread1 = new MyThread();
Thread thr = new Thread(thread1, "thread");
thr.start();
System.out.println(thr.currentThread().getName());
System.out.println(thr.getName());//Why do I have access to this method?
}
}