public class Thread7 implements Runnable {
public static void main(String r[]) {
Thread t = new Thread(new Thread7());
t.start();
public void run() {
System.out.println("C");
System.out.println("D");
}
System.out.println("A");
try {
t.join();
System.out.println("B"); }
catch(Exception e){}
}
}
Query1: On compiling this program I get "illegal start of expression" error pointing to public void run. But when I remove that block of code and place it outside main() the program compiles and runs successfully. What is the rule behind it?
Query2: After I place run() outside main() the output is ACDB. What I don't understand is after t.start() is invoked shouldn't the control transfer first to run() block and print CD first then followed by AB?