Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread

 
Hasitha Randika
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A extends Thread{
public void main(){
System.out.println("A");
}
A(Runnable r){
super(r);
}
A(){

}
}
class B implements Runnable{
public void run(){
System.out.println("B");
}
}
class C{
public static void main(String ar[]){
A a = new A();
B b = new B();
Thread t =new Thread();
a.start();
b.start();// this is a compilation error //line 1
t.start();
}
}
in the above code syntax line 1 gives a compile error why's that?
do i have to use a construcor if i implement the runnable interface
 
Vas Golla
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new Thread(b).start();
will work if used Runnable.
You tried to call start() on a Runnable where as start() is to be from a Thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic