• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Thread Question  RSS feed

 
Billy Hickory
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between using the class object(line 1) and the Thread object(line 2) when executing start?
public class Borley extends Thread{
public static void main(String argv[]){
Borley b = new Borley(); //1
//Thread b = new Borley(); //2
b.start();
}
public void run(){
System.out.println("Running");
}
}
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you define:
Borley b = new Borley (...);
you may access every visible method (depending on priv/prot/pub/default) of Borley.
But if you say:
Thread t = new Borley (...);
your t 'sees' only the subset of Borley, which is a Thread.
This protects the user of doing more with this 't', as intended, and allows you, to put the 't' to every method, which expects a Thread (and never heard of Borley before).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!