Este hilo no funciona
Publicado por Oscar Avendaño (3 intervenciones) el 05/07/2004 15:34:13
public class Multihola
{
class TestTh extends Thread
{
private String nombre;
private int retardo;
public TestTh(String s, int d)
{
nombre=s;
retardo=d;
}
public void run()
{
try
{
sleep(retardo);
}
catch(InterruptedException e)
{
}
System.out.println("Hola mundo"+nombre+" "+retardo);
}
}
public static void main(String args[])
{
TestTh t1,t2,t3;
t1=new TestTh("Thread 1",(int)(Math.ramdon()*2000));
t2=new TestTh("Thread 2",(int)(Math.ramdon()*2000));
t3=new TestTh("Thread 3",(int)(Math.ramdon()*2000));
t1.start();
t2.start();
t3.start();
}
}
Entrega el siguiente mensaje
Multihola.java:32: non-static variable this cannot be referenced from a static context
t1=new TestTh("Thread 1",(int)(Math.ramdon()*2000));
Por favor alguien que me enseñe, que está pasando
atte
O.Avendaño
{
class TestTh extends Thread
{
private String nombre;
private int retardo;
public TestTh(String s, int d)
{
nombre=s;
retardo=d;
}
public void run()
{
try
{
sleep(retardo);
}
catch(InterruptedException e)
{
}
System.out.println("Hola mundo"+nombre+" "+retardo);
}
}
public static void main(String args[])
{
TestTh t1,t2,t3;
t1=new TestTh("Thread 1",(int)(Math.ramdon()*2000));
t2=new TestTh("Thread 2",(int)(Math.ramdon()*2000));
t3=new TestTh("Thread 3",(int)(Math.ramdon()*2000));
t1.start();
t2.start();
t3.start();
}
}
Entrega el siguiente mensaje
Multihola.java:32: non-static variable this cannot be referenced from a static context
t1=new TestTh("Thread 1",(int)(Math.ramdon()*2000));
Por favor alguien que me enseñe, que está pasando
atte
O.Avendaño
Valora esta pregunta


0