Question:What is the output of the given program?
public class Test89 {
        public static void main(String[] args) {
                T x = new T("X", null); x.start();
                T y = new T("Y", x); y.start();
                T z = new T("Z", y); z.start();
        }
}
class T extends Thread {
        private Thread predecessor;
        private String name;
        public T(String name, Thread predecessor) { 
                this.predecessor = predecessor; 
                this.name = name; 
        }
        public void run() {
                try {
                        Thread.sleep((int)(Math.random()*89));
                        System.out.print(name);
                } catch (InterruptedException ie) {
                        ie.printStackTrace();
                }
        }
}
 

A always XYZ 

B always ZYX 

C any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX 

D any of the following: XYZ, ZYX 

+ Answer
+ Report
Total Preview: 1317

Copyright © 2024. Powered by Intellect Software Ltd