2. The method that must be defined by a class implementing the lang.runnable interface?
- void run()
- public void start()
- void run(int priority)
- public void run()
Answer: Option D
Solution: The proper choice is D since, by default, all methods in an interface are abstract and must be overridden by the class that implements the interface. Only the void run() function, the sole method of the Runnable interface, has to be implemented. Because they narrow the access privileges—that is, package(default) access is smaller than public access—Options A and C are wrong. Option B is wrong because it is not a method in the Runnable interface.
3.Which of the following will contain the body of the thread?
- run();
- start();
- stop();
- main();
Answer: Option A
Solution: The best choice is option A. A thread's run() method is comparable to an application's main() method. The run method of the object is called in that independently running thread as soon as the thread is started. Option B is incorrect. This thread's run method is called by the Java Virtual Machine when the start() method is invoked. Option C is incorrect. Deprecated is the stop() method. It compels the thread to halt its operation. Option D is incorrect; main () is a program's primary point of entry.
4.Which method is used to start the thread execution?
- init();
- resume();
- run();
- start();
Answer: Option D
Solution: The right answer is D. This thread's run method is called by the Java Virtual Machine when the start() method is invoked. Option A is incorrect. The Thread class doesn't have an init() function. Option C is incorrect. A thread's run() method is comparable to an application's main() method. The run method of the object is called in that independently running thread as soon as the thread is started. Option B is incorrect. Deprecated is the resume() method. A suspended thread is picked back up.
5. Which cannot directly cause a thread to stop executing?
- Calling the SetPriority()method on a Thread
- Calling the wait()method on an object.
- Calling notify()method on an object.
- Calling read()method on an InputStream
Answer: Option C
Solution: The correct answer is choice C which is notify() function call that wakes up a single thread which is waiting on its object.
Comments
write a comment