What is the output of the following code?
// Test.java: Define threads using the Thread class
public class Test {
/** Main method */
public static void main(String[] args) {
}
public Test() {
| PrintChar printA = new PrintChar('a', 4); |
| PrintChar printB = new PrintChar('b', 4); |
}
class PrintChar implements Runnable {
| private char charToPrint; // The character to print |
| private int times; // The times to repeat |
| /** Construct a thread with specified character and number of |
| times to print the character |
| public PrintChar(char c, int t) { |
| /** Override the run() method to tell the system |
| for (int i = 0; i < times; i++) |
System.out.print(charToPrint);
}
}
◦ character a and b are randomly printed
◦ ababababab
◦ bbbbbaaaaa
◦ aaaaabbbbb