Check this code it is compiling and running fine
1.class th extends
Thread 2.{
3.public static void main(
String args[])
4.{
5.th A =new th();
6.Thread t1 = new Thread(A);
7.Thread t2 = new Thread(A);
8.t1.start();
9.}
10.public void run()
11.{
12.int x=5,y=5;
13.for(int i =0 ; i<5;i++)
15.{
16.System.out.println(x+""+y);
17.}
18.}
19.}
At line 5 we are constructing a thread which is referred by A (as th is subclass of Thread so A is a Thread).
At line 6 and 7 we are passing this Thread A as argument to constructor's of t1 and t2,as for I know there is no constructor in the thread class which takes a Thread a parameter.
But this code is compiling and running also.
Can any body explain me how?
And one more thing this code of 19 lines, if I add two more methods to this app then it will become more that 25 line, is this is the way sun ask 25+ lines of code in the Real exam.
Will only a brace can be in a line as in above code (lines 2,4,9,7 etc)?
Who took the Real Exam please help me.
Every body (who cleared the
scjp) are saying that Threads are tough tough tough what they me by though, is sun asking questions in a tricky way or code is lengthy i.e. 25+ lines or some thing else. Acutely what they mean by saying tough, please help me?