Computer Knowledge

Java Core Classes and Threads

1,935 Questions

Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.

String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules

Java Core Classes and Threads Questions

Multiple choice
  1. class MyClass extends Runnable { public void run() { } }

  2. class MyClass implements Thread { public void run() { } }

  3. class Thread MyClass { public void run() { } }

  4. class MyClass extends Thread { public void run() { } }

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The correct structure is: class MyClass extends Thread {       public void run()       {       } }

Multiple choice
  1. IllegalMonitorException

  2. IllegalStateException

  3. IllegalMonitorStateException

  4. IllegalMonitorOwnStateException

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

All these methods must be called only when they own the monitor of that object, otherwise they throw IllegalMonitorStateException exception. These methods are used for proper coordination among the threads.

Multiple choice
  1. Destroy this thread, without any clean-up

  2. Destroy this thread, with clean-up

  3. Destroy all threads, without any clean-up

  4. Destroy all threads, with clean-up

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The destroy() method of thread class destroys this thread, without any clean-up.

Multiple choice
  1. ArrayIndexOutOfBoundsException

  2. ArrayIndexOutOfBoundsExceptions

  3. ArrayIndexOutOfBoundException

  4. ArrayOutOfBoundsException

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The ArrayIndexOutOfBoundsException occurs if one is trying to access an element of array with an index that is larger than the range. For example: int Num[]={0,2,3}; Num[5]=0; /This statement throws the exception/