Tag: programming languages

Questions Related to programming languages

If you call the interrupted() method of a thread object twice the second call will always return false.

  1. True

  2. False


Correct Option: B
  1. The thread that has been waiting the longest.

  2. The thread that was the last one to to exit the monitor.

  3. You can never be sure which thread will get to run first.

  4. The the first thread that called the wait() method


Correct Option: C

Which of these are valid contructors of a Thread object.

  1. public Thread(Object obj)

  2. public Thread(String name)

  3. public Thread(Runnable trgt)

  4. public Thread(ThreadGroup grp, Runnable trgt, String name)

  5. public Thread(ThreadGroup grp, Object ob)


Correct Option: B,C,D

public class test { Line 1. public static void main(String [] a) { Line 2. assert a.length == 1; Line 3. } Line 4. } Which two will produce an AssertionError? (Choose two.) A. java test B. java -ea test C. java test file1 D. java -ea test file1 E. java -ea test file1 file2 F. java -ea:test test file1

  1. AB

  2. BC

  3. AE

  4. BE


Correct Option: D

Line 1. public class ClassA { Line 2. public void count(int i) { Line 3. count(++i); Line 4. } Line 5. } And: Line 6. ClassA a = new ClassA(); Line 7. a.count(3); Which exception or error should be thrown by the virtual machine? A. StackOverflowError B. NullPointerException C. NumberFormatException D. IllegalArgumentException E. ExceptionlnlnitializerError

  1. A

  2. B

  3. C

  4. D


Correct Option: D
  1. public abstract class Canine { public Bark speak(); }

  2. public abstract class Canine { public Bark speak() { } }

  3. public class Canine { public abstract Bark speak(); }

  4. public class Canine abstract { public abstract Bark speak(); }


Correct Option: B
  1. X extends Y is correct if and only if X is a class and Y is an interface.

  2. X extends Y is correct if and only if X is an interface and Y is a class.

  3. X extends Y is correct if X and Y are either both classes or both interfaces.

  4. X extends Y is correct for all combinations of X and Y being classes and/or interfaces.


Correct Option: C