java - getName() from class Thread -
why have access getname()
method? class doesn't extends class thread
implements interface runnable
.
public class mythread implements runnable { public void run() { system.out.println("mythread 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 have access method? } }
you're not calling getname() on instance of mythread class, you're calling on instance of thread class. should consider renaming class myrunnable because mythread seem class sort of thread class, while isn't.
Comments
Post a Comment