AmbitionBox
Discover Best Places to work in India
Discover best places to work
Compare & find best workplace
Bring your workplace to life
Highlight your company's perks
Read reviews for 6L+ companies
Rate your former or current company
Discover salaries for 8L+ companies
Calculate your take home salary
Check your market value
Help other jobseekers
Read interviews for 90K+ companies
Interviews questions for 1K+ colleges
Contribute your interview questions
Java Programming
Which of the following methods is not defined in the Thread class?
A. yield ( )
B. sleep (..)
C. run ( )
D. wait ( )
What would happen when a thread executes the following statement in its run() method?
sleep(500);
A. It is going to stop execution and restart execution exactly after 500 milliseconds.
B. It is going to stop execution and restart execution not earlier than 500 milliseconds.
C. It will result in compiler error because sleep ( ) method cannot be called inside run ( ) method.
D. It will result in compiler error because the sleep ( ) method does not take any argument.
Consider the following code fragment:
1. public class ThreadTest {
2. public static void main(String[] args) {
3. Counter ct = new Counter();
4. ct.start();
5. System.out.println("The thread has been started");
6. }
7. }
8. class Counter extends Thread {
9. protected void run() {
10. System.out.println("Hello");
11. }
12. }
What would be the output of this code fragment?
A. The thread has been started.
Hello
B. Hello
The thread has been started.
C. Either A or B
D. Compiler error on line 9
Consider the following code:
1. public class ThreadOrder {
2. static int count=0;
3. public static void main(String[] args) {
4. Counter ct = new Counter();
5. Tracker trk1 = new Tracker(ct, "thread one");
6. Tracker trk2 = new Tracker(ct, "thread two");
7. trk1.start();
8. trk2.start();
9. }
10.}
11. class Tracker extends Thread {
12. Counter ct;
13. String message;
14. Tracker(Counter ct, String msg) {
15. this.ct = ct;
16. message = msg;
17. }
18. public void run() {
19. System.out.println(message);
20. }
21. }
22. class Counter {
23. private int count=0;
24. public int nextCounter() {
25. synchronized(this) {
26. count++;
27. return count;
28. }
29. }
30. }
A. thread 1
thread 2
B. thread 2
thread 1
C. Sometimes A, sometimes B
D. Runtime exception on line 8
Which of the following is a method of the Object class?
Which of the following methods guarantee putting a thread out of the running state?
A. wait ( )
B. yield ( )
C. kill ( )
D. notify ( )
Which of the following is an invalid Thread constructor?
A. Thread ( )
B. Thread ( into millisec)
C. Thread ( Runnable r)
D. Thread ( Runnable R, String name)
Join India’s largest community to research company culture
Are you a student or working professional?
Student/Never worked
I am a student/I have never worked
Working Professional
I am working/I have worked before
What are your preferred job locations?
Popular Cities
Other Cities
Follow your preferred designations/job profiles
Suggestions based on your job profile
vs
Similar Companies