* Write a Java Program to give the example of Thread .
class Pankaj extends Thread{
public void run(){
try{
int i=0;
while(i<=4){
System.out.println("Good Morning Pankaj ");
Thread.sleep(4000);
}
}
catch(InterruptedException e){
System.out.println("Good Afternoon Pankaj Kumar");
}
}
}
class Priyanshu extends Thread{
public void run(){
try{
int i=0;
while(i<=3){
System.out.println("Good Morning Priyanshu");
Thread.sleep(3000);
}
}
catch(InterruptedException e){
System.out.println("Good Afternoon Priyanshu");
}
}
}
class TestThread{
public static void main(String args[]){
Pankaj P=new Pankaj();
Priyanshu P1=new Priyanshu();
P.start();
P1.start();
}
}
output
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
Good Morning Pankaj
Good Morning Priyanshu
No comments:
Post a Comment