4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by BestJewSinceJC
0

It's legal to overload any method anywhere, but it probably won't do what you want. What you're supposed to do is override the run method. See here

0

What you're supposed to do almost certainly (there's hardly ever a need to derive from Thread) is to create a new class that implements Runnable and implement the run() method in that.

0
/* Ok...whats wrong in this code ? */


import java.io.*;

class Pat extends Thread
{
public static int cnt=0;
}
class Pattern1 extends Pat

{

    public void run()
    {
    for(int i=1;i<=8;i++)
    {
       System.out.print("|");
       cnt++;

        try
        {
         wait();
        }
        catch(InterruptedException e)
        {
        } if(cnt>i)
           resume();                    
    }
    }
} 

class Pattern2 extends Pat

{
    public void run()
    {
    for(int i=1;i<=7;i++)
    {
       System.out.print("*");
     try
        {
         wait();
        }
        catch(InterruptedException e)
        {
        }
    if(cnt>i+1)
    resume();
    cnt++;
    }

    }
} 

class Pattern

{
    public static void main(String args[])
    {
    Pattern1 p1=new Pattern1();
    Pattern2 p2=new Pattern2();

    p1.setPriority(10);
    p2.setPriority(8);

    p1.start();
    p2.start();

    }
}

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.