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

  • All Known Subinterfaces:RunnableFuture, RunnableScheduledFutureAll Known Implementing Classes:AsyncBoxView.ChildState, ForkJoinWorkerThread, FutureTask, RenderableImageProducer, SwingWorker, Thread, TimerTask
    public interface Runnable

    The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method of no arguments called run.

    This interface is designed to provide a common protocol for objects that wish to execute code while they are active. For example, Runnable is implemented by class Thread. Being active simply means that a thread has been started and has not yet been stopped.

    In addition, Runnable provides the means for a class to be active while not subclassing Thread. A class that implements Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the target. In most cases, the Runnable interface should be used if you are only planning to override the run[] method and no other Thread methods. This is important because classes should not be subclassed unless the programmer intends on modifying or enhancing the fundamental behavior of the class.

    Since:JDK1.0See Also:Thread, Callable

    • Method Summary

      Methods Modifier and TypeMethod and Description
      void 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.

    • Method Detail

      • run

        void 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.

        See Also:Thread.run[]

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2020, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

  • HOME
  • QUIZ
  • CONTACT US

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 method 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.

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 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.

Which method will start the thread?

Summary.

Chủ Đề