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. public class MyRunnable extends Runnable{public void run(){}}

  2. public class MyRunnable extends Object{public void run(){}}

  3. public class MyRunnable implements Runnable{public void run(){}}

  4. public class MyRunnable implements Runnable{void run(){}}

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

The class correctly implements the Runnable interface with a legal public void run()method. Option 1 is incorrect because interfaces are not extended; they are implemented. Option 2 is incorrect because even though the class would compile and it has a validpublic void run() method, it does not implement the Runnable interface, so the compiler would complain when creating a Thread with an instance of it. Option 4 is incorrect because the run() method must be public.