- 1

Please review this question. As sololearner app is keep on rejecting it n Don't down vote question, if you don't understand it.!

What are possible outputs of following code. Class MyThread extends Thread{ public void start(){ super.start(); System.out.print("S") ; } public void run(){ System.out.print("R"); } } class demo{ public static void main(String[] args){ MyThread t = new MyThread (); t.start(); System. out.print("M"); } } answers are : SRM, SMR, RSM. but not MRS

19th Apr 2017, 5:55 PM
ram kumar
ram kumar - avatar
2 Respuestas
+ 2
The question is totally correct and , in fact interesting and it requires deep java knowledge to solve it. unfortunately, questions are voted by the community, and a lot of people just did the the tutorial here so they can't know it:(. I also got an question about generics (with extends and super and multiple types) restricted:( As a result most challang question are just about solving loops and not about beeing a java expert with in depth knowledge of the library and features like lamdas and generics. your other question was also correct and interesting.
19th Apr 2017, 7:30 PM
No One
No One - avatar
0
explanation: there are 2 threads. main and t thread. main will print both S n M. Where R is printed by t Thread only. So, M has to always follows S, may not be immediately. as t is a child thread to main, they will have same priorities. So, R may come before or after S or M. depends up on the JVM we use. note : please do observe that, here t.start() calls overriden start() method of MyThread class. which will be executed by main thread only. t thread will not be initiated until super.start() is executed.
19th Apr 2017, 6:06 PM
ram kumar
ram kumar - avatar