Aim:-  Create a java program with multithreading. One
thread will print “Good Morning” and sleep for 1s And second thread will print
“Good Evening” and sleep for 1s.
JAVA Code :-
import java.lang.*;
class morning extends Thread
{
 
morning() {
    super("Morning");
    System.out.println("\n" +this);
    start();
 
}
 
public void run() {
    try {
              System.out.println("Good
Morning...");
              sleep(5000);
    }
    catch(InterruptedException e) {
            System.out.println("morning
interrupted ");
    }
 
}
}
class evening extends Thread
{
  
evening() {
    super("Evening");
    System.out.println("\n" +this);
    start();
 
}
 
public void run() {
    try {
              System.out.println("Good
Evening....");
              sleep(5000);
    }
    catch(InterruptedException e) {
            System.out.println("evening
interrupted ");
    }
 
}
}
class MorEve
{
 
public static void main(String args[])
 
{   
     morning m=new morning();
     evening e=new evening();
 
}
}
Output:-

No comments:
Post a Comment