Which of the following method will start this thread public class my thread implements runnable?

  • HOME
  • QUIZ
  • CONTACT US

Which of the following method will start this thread public class my thread implements runnable?

EXAMIANS

Nội dung chính

  • JAVA Threads
  • JAVA Threads Which of the following constructor of class Thread is valid one?
  • JAVA Threads What is the output for the below code ?public class Test extends Thread{ public static void main(String argv[]){ Test t = new Test(); t.run(); } public void start(){ for(int i = 0; i < 10; i++){ System.out.println("Value of i = " + i); } }}
  • JAVA Threads Analyze the following code:public class Test implements Runnable{ public static void main(String[] args){ Test t = new Test(); t.start(); } public void run() { }}
  • JAVA Threads Given the code. What will be the result?public class Test implements Runnable{ public static void main(String[] args) throws InterruptedException{ Thread a = new Thread(new Test()); a.start(); System.out.print("Begin"); a.join(); System.out.print("End"); } public void run(){ System.out.print("Run"); }}
  • JAVA Threads What notifyAll() method do?
  • What will be the output of program class A implements runnable?
  • Which of the following methods will start this thread public class my thread implements runnable?
  • How does run () method in runnable work?
  • Does thread implement runnable?

  • COMPUTER
  • CURRENT AFFAIRS
  • ENGINEERING
    • Chemical Engineering
    • Civil Engineering
    • Computer Engineering
    • Electrical Engineering
    • Mechanical Engineering
  • ENGLISH GRAMMAR
  • GK
  • GUJARATI MCQ

JAVA Threads

Compilation fails with an error at line 5

good

None of these

Compilation succeed but Runtime Exception

null

Compilation fails with an error at line 5

good

None of these

Compilation succeed but Runtime Exception

null

ANSWER DOWNLOAD EXAMIANS APP

JAVA Threads Which of the following constructor of class Thread is valid one?

Thread(int priority)

Thread(Runnable threadOb, int priority)

None of these

Thread(String threadName, int priority)

Thread(Runnable threadOb, String threadName)

Thread(int priority)

Thread(Runnable threadOb, int priority)

None of these

Thread(String threadName, int priority)

Thread(Runnable threadOb, String threadName)

ANSWER DOWNLOAD EXAMIANS APP

JAVA Threads What is the output for the below code ?public class Test extends Thread{ public static void main(String argv[]){ Test t = new Test(); t.run(); } public void start(){ for(int i = 0; i < 10; i++){ System.out.println("Value of i = " + i); } }}

A run time error indicating that no run method is defined for the Thread class

A compile time error indicating that no run method is defined for the Thread class

Clean compile but no output at runtime

Clean compile and at run time the values 0 to 9 are printed out

None of these

A run time error indicating that no run method is defined for the Thread class

A compile time error indicating that no run method is defined for the Thread class

Clean compile but no output at runtime

Clean compile and at run time the values 0 to 9 are printed out

None of these

ANSWER DOWNLOAD EXAMIANS APP

JAVA Threads Analyze the following code:public class Test implements Runnable{ public static void main(String[] args){ Test t = new Test(); t.start(); } public void run() { }}

The program compiles, but it does not run because the run() method is not implemented.

The program compiles and runs fine.

The program does not compile because the start() method is not defined in the Test class.

The program compiles, but it does not run because the start() method is not defined.

The program compiles, but it does not run because the run() method is not implemented.

The program compiles and runs fine.

The program does not compile because the start() method is not defined in the Test class.

The program compiles, but it does not run because the start() method is not defined.

ANSWER DOWNLOAD EXAMIANS APP

JAVA Threads Given the code. What will be the result?public class Test implements Runnable{ public static void main(String[] args) throws InterruptedException{ Thread a = new Thread(new Test()); a.start(); System.out.print("Begin"); a.join(); System.out.print("End"); } public void run(){ System.out.print("Run"); }}

"BeginEndRun" is printed.

"BeginRunEnd" is printed.

"BeginEnd" is printed.

An exception is thrown at runtime.

Compilation fails.

"BeginEndRun" is printed.

"BeginRunEnd" is printed.

"BeginEnd" is printed.

An exception is thrown at runtime.

Compilation fails.

ANSWER DOWNLOAD EXAMIANS APP

JAVA Threads What notifyAll() method do?

Wakes up all threads that are waiting on this object's monitor

Wakes up all threads that are not waiting on this object's monitor

Wakes up one threads that are waiting on this object's monitor

None of these

Wakes up all threads that are waiting on this object's monitor

Wakes up all threads that are not waiting on this object's monitor

Wakes up one threads that are waiting on this object's monitor

None of these

ANSWER DOWNLOAD EXAMIANS APP

MORE MCQ ON JAVA Threads

What will be the output of program class A implements runnable?

3. What will be the output of the program? Explanation: If a Runnable object is passed to the Thread constructor, then the run method of the Thread class will invoke the run method of the Runnable object. ... Exercise :: Threads - Finding the output..

Which of the following methods will start this thread public class my thread implements runnable?

Java Thread start() method The start() method of thread class is used to begin the execution of thread.

How does run () method in runnable work?

run. When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread. The general contract of the method run is that it may take any action whatsoever.

Does thread implement runnable?

The Thread class itself implements Runnable with an empty implementation of run() method. For creating a new thread, create an instance of the class that implements Runnable interface and then pass that instance to Thread(Runnable target) constructor.

Which of the following methods will start this thread public class?

start(); [D]. Explanation: Because the class implements Runnable, an instance of it has to be passed to the Thread constructor, and then the instance of the Thread has to be started.

Which method is used to start the thread?

Introduction.

How do I start a thread implementing runnable?

To use the Runnable interface to create and start a thread, you have to do the following:.
Create a class that implements Runnable ..
Provide a run method in the Runnable class..
Create an instance of the Thread class and pass your Runnable object to its constructor as a parameter..
Call the Thread object's start method..

Which of the following will start this thread?

Option B is Correct. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.