A)
class Mythread extends Thread
{
public void run()
{
if(getName().equals("one"))
for(int i=1;i<=10;i++)
System.out.println(i);
if(getName().equals("three"))
for(int j=11;j<=20;j++)
System.out.println(j);
}
}
classMultiThreadingApplication1 {
public static void main(String[] args) {
Mythread t1= new Mythread();
Mythread t2=new Mythread();
t1.setName("one");
t2.setName("three");
t1.start();
t2.start();
}
}
->here getName() is calling by run(). So, it is not calling by using any reference because on which object that runs is calling on that object contain the getName().
Comments
Post a Comment