3:53 pm - Saturday March 25, 2547

Thread Example program for getName()

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
@Author: Candidjava.com
*Two threads extended from Thread Class.
*Object  created for our two threads in Main class
*called getName method for both thread classes using their objects.
*Output printed as our thread names.
class  Myclass extends Thread                               //  Myclass extended  from  thread
public  void run()
System.out.println("My class");
 }                                                                                    // end  of Myclass
class SecondClass extends Thread                        //  Second class extended  from  thread
public  void run()
System.out.println("Second class");
}                                                                                            // end  of SecondClass
public class  ThreadgetName
public  static void main(String args[])throws Exception
Myclass s1 = new Myclass();                                          //Object  created  for Myclass
String c =s1.getName();
System.out.println("Myclass Name="+c);                      // My class Name is printed here;
SecondClass s2=new SecondClass();                        //Object  created  for SecondClass
String b=s2.getName();
System.out.println("Second priority="+b);    // SecondClass Name is printed here;


My class
Myclass Name=Thread-0
Second class
Second priority=Thread-1

Filed in: Z-A All Java Codes

Comments are closed.