Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String args[])
- {
- try
- {
- myClass test = new Thread(new myClass(stuff));
- test.start();
- test.join();
- }
- catch (Throwable t) { }
- }
- Thread test = new Thread(new myClass(stuff));
- teste.start();
- teste.join();
- public class MyRunner implements Runnable
- {
- @Override public void run();
- public void somethingElse();
- }
- Runnable r = new MyRunner();
- r.somethingElse(); // won't work, this method not defined by Runnable.
- MyRunner m = new MyRunner();
- m.somethingElse(); // success!
- class MyRunnable implements Runnable() {
- public void run() { /* do run stuff */ }
- public void print() { /* do print stuff */ }
- }
- class MyThread extends Thread() {
- public void run() { /* do run stuff */ }
- public void print() { /* do print stuff */ }
- }
- Thread t = new Thread(new MyRunnable());
- t.start();
- t.print(); // error, t is a Thread not a MyRunnable and not a MyThread
- t.join();
- MyRunnable mr = new MyRunnable();
- mr.run(); // doesn't run in its own thread
- mr.print(); // this is ok
- Runnable r = new MyRunnable();
- r.run(); // doesn't run in its own thread
- r.print(); // error, r is defined as Runnable which has no print() method
- MyThread mt = new MyThread();
- mt.start();
- mt.print(); // this is ok because mt is a MyThread
- mt.join();
- myClass test = new Thread(new myClass(stuff));
- Thread test = new Thread(new myClass(stuff));
- public static void main(String args[])
- {
- try
- {
- myClass foo = new myClass(stuff);
- myClass test = new Thread(foo);
- test.start();
- test.join();
- foo.print();
- }
- catch (Throwable t) { }
- }
Add Comment
Please, Sign In to add comment