Given:
2. public class Main extends Thread { 3. public static long id; 4. public void run() { 5. for(int i = 0; i < 4; i++) { 6. // insert code here 7. new Thread(new Main()).start(); 8. throw new Error(); 9. } /* w w w . j av a2s . c o m*/ 10. System.out.print(i + " "); 11. } } 12. public static void main(String[] args) { 13. Thread t1 = new Main(); 14. id = t1.getId(); 15. t1.start(); 16. } }
And the two code fragments:.
I. if(i == 2 && id == Thread.currentThread().getId()) { II. if(i == 2) {
When inserting either fragment, independently at line 6, which are true? (Choose all that apply.)
E is correct.
In either case, before the Error is thrown a new thread is created, and the new thread will execute independently of the Error.
A and B are incorrect because fragment II creates a sort of recursive, endless loop.
C and D are incorrect based on the above.