Wednesday, March 11, 2020

WEEK 6 ASSIGNMENT SOLUTION

QUESTION 1:

// Write the appropriate code to extend the Thread class to complete the class Question61.
public class Question61 extends Thread{

public void run()
{
  System.out.print("Thread is Running.");
}

QUESTION 2:

// Create main class Question62 with main() method and appropriate statements in it
public class Question62{
  public static void main(String[] args){
    ThreadRun a = new ThreadRun();
    Thread b = new Thread(a);
    b.start();
  }
}


QUESTION 3:

// Create a class named MyThread and extend/implement the required class/interface

// Define a method in MyThread class to print the output

class MyThread extends B
{
  public void run()
  {
    System.out.print("NPTEL Java");
  }
}

QUESTION 4:

synchronized void print(int n){
   for(int i=1;i<=5;i++){ 
     System.out.println(n*i); 
     try{ 
      Thread.sleep(400); 
     }catch(Exception e){
        System.out.println(e);
     } 
   }
 } 


QUESTION 5:

// Write the necessary code below...
t.setPriority(Thread.MAX_PRIORITY);
t.start();
t.setName("NPTEL");

0 Comments:

Post a Comment