Tuesday, August 14, 2007

Java Puzzlers

Hi
see this .. best java puzzles ever
http://video.google.com/videoplay?docid=9214177555401838409
wat say ??

Adding my bit of cheese on it try predicting output of


class Some_Runnable implements Runnable {
public void run() {
System.out.println("Some_Runnable");
}
}

class Some_Thread extends Thread {
Some_Thread() {}
Some_Thread(Runnable r) {
super(r);
}
public void run() {
System.out.println("Some_Thread");
}
}

class Some_Other_Thread extends Thread {
Some_Other_Thread() {}
Some_Other_Thread(Runnable r) {
super(r);
}
public void run() {
System.out.println("Some_Other_Thread");
}
}

class default_thread extends Thread {
default_thread() {
System.out.println("IN default thread ");
}
default_thread(Runnable r ){
super(r);
}
// NO RUN() METHOD
}

public class Class2 {
public static void main(String args[]) {
// lang.Thread class implements Runnable
new Some_Thread().start();
new Some_Thread(new Some_Runnable()).start();
new Some_Thread(new Some_Other_Thread()).start();

new Thread(new Some_Runnable()).start();
new Thread(new Some_Other_Thread()).start();

System.out.println("Default Thread ... doesnt override run()");
new default_thread().start(); // ok
new default_thread(new Some_Runnable()).start();
new default_thread(new Some_Other_Thread()).start();

}
}

No comments: