Skip to main content

The code given below calls the run () method of two threads while setting their priority. Will this code compile successfully? If not, correct the


Code.
class t1 extends Thread
{
  public void run()
  {
    System.out.println("This is Thread1 class");
  }
}
class t2 extends Thread
{
  public void run()
  {
   System.out.println("This is Thread2 class");
  }
}
public class ThreadP
{
  public static void main(String args[])
  {
   t1 t=new t1();
   t2 tt=new t2();
   t.setPriority(Thread.MIN_PRIORITY);
   tt.setPriority(Thread.MIN_PRIORITY);
   t.run();
   tt.run();
  }
}
Output:

Comments

Popular posts from this blog

Program to calculate the room area and volume to illustrate the concept of single inheritance.

CODE: class Roomarea   { protected double l, b; Roomarea(double len, double br) { l=len; b=br; } void putdata() { System.out.println("Area of Room: "+(l*b)); } } class Roomvol extends Roomarea   { double h; Roomvol(double len, double br, double he) { super(len, br); h=he;   } void putdata() { super.putdata(); System.out.println("Volume of Room: "+(l*b*h)); } } public class EXP18Q4 { public static void main(String[] args) { Roomvol r1 = new Roomvol(10, 20, 10); r1.putdata();   } }

Develop an applet for drawing a human face.

Code: import java.awt.*; importjava.applet.*; /* <applet code = "face" width = 300 height = 300></applet> */ public class face extends Applet {     public void paint(Graphics g)     { g.drawOval(40, 40, 120, 150); g.drawOval(57, 75, 30, 20); g.drawOval(110, 75, 30, 20); g.fillOval(68, 81, 10, 10); g.fillOval(121, 81, 10, 10); g.drawOval(85, 100, 30, 30); g.fillArc(60, 125, 80, 40, 180, 180); g.drawOval(25, 92, 15, 30); g.drawOval(160, 92, 15, 30);     } } Output:

Develop a program using control loops in applets.

Code: import java.awt.*; import java.applet.*; public class Control extends Applet {      public void paint(Graphics g)      {      for(int i=1;i<=4;i++)     {          if(i%2==0)         {            g.fillOval(90,i*50+10,50,50);           g.setColor(Color.black);        }        else       {          g.fillOval(90,i*50+10,50,50);          g.setColor(Color.red);       }    }   } } /* <applet code=Control width=300 height=300> </applet> */ Output: