Java SE - Sample Interview Question (Senior Level)

 What will be the output of the following program?

public class Test {

          public static void main(String[] args)
                  throws InterruptedException {

                    JoinThread t1 = new JoinThread("one");
                    JoinThread t2 = new JoinThread("two");

                    t1.start();
                    t1.join();
                    t2.start();
          }
}

class JoinThread extends Thread{

          public JoinThread(String name){
                  super(name);
          }

          public void run(){

                    for(int i=0; i<5; i++){
                            System.out.println(getName());
                    }
          }

}

  1. The program will output the message 'one' five times followed by the message 'two' five times
  2. The program will output the message 'two' five times followed by the message 'one' five times
  3. The program will output the messages 'one' and 'two' in a random order (each five times)
  4. The program will only output the message 'one' five times
Tests in Java SE for Seniors

Test Name Difficulty Time (minutes) No. of Questions
Java Online Test for Seniors Java Senior 60 30

More Specific Tests in Java SE for Seniors

Test Name Difficulty Time (Minutes) No. of Questions
Java-SE-Generics Online Test for Seniors Java - Generics Senior 20 10
Java-SE-Language-Fundamentals Online Test for Seniors Java - Language Fundamentals Senior 20 10
Java-SE-Collections-Framework Online Test for Seniors Java - Collections Framework Senior 20 10
Java-SE-Reflection Online Test for Seniors Java - Reflection Senior 20 10
Java-SE-Object-Serialization Online Test for Seniors Java - Object Serialization Senior 20 10
Java-SE-Concurrency-Utilities Online Test for Seniors Java - Concurrency Utilities Senior 20 10
Java-SE-I/O Online Test for Seniors Java - I/O Senior 20 10
Java-SE-Networking Online Test for Seniors Java - Networking Senior 20 10
Java-SE-Security Online Test for Seniors Java - Security Senior 20 10