Sunday, January 12, 2014

Example of setName() and getName()

class Thread12 extends Thread
{
public void run()
{
System.out.println("Running....");
}
public static void main(String surat[])
{
Thread12 t1=new Thread12();
Thread12 t2=new Thread12();

System.out.println("Name of t1 : "+t1.getName());
System.out.println("Name of t2 : "+t2.getName());

t1.start();
t2.start();

t1.setName("Lallllooooooo");
System.out.println("After changing the name of t1 : "+t1.getName());
t2.setName("Panchoooooooo");
System.out.println("After changing the name of t2 : "+t2.getName());
}
}

Output:

No comments:

Post a Comment