1. Which two can be used to create a new Thread? Extend java.lang.Thread and override the run() method. Extend java.lang.Runnable and override the start() method. Implement java.lang.Thread and implement the run() method. Implement java.lang.Runnable and implement the run() method. Implement java.lang.Thread and implement the start() method.





Ask Your Doubts Here

Type in
(Press Ctrl+g to toggle between English and the chosen language)

Comments

  • By: guest on 02 Jun 2017 01.26 am
    There are two ways of creating a thread; extend (sub-class) the Thread class and implement the Runnable interface. For both of these ways you must implement (override and not overload) the public void run() method. (1) is correct - Extending the Thread class and overriding its run method is a valid procedure. (4) is correct - You must implement interfaces, and runnable is an interface and you must also include the run method. (2) is wrong - Runnable is an interface which implements not Extends. Gives the error: (No interface expected here) (3) is wrong - You cannot implement java.lang.Thread (This is a Class). (Implements Thread, gives the error: Interface expected). Implements expects an interface. (5) is wrong - You cannot implement java.lang.Thread (This is a class). You Extend classes, and Implement interfaces. (Implements Thread, gives the error: Interface expected)
Show Similar Question And Answers
QA->Which scheme was launched by the Indian Government to create a hunger free India?....
QA->Hibi method is used for the farming of _____?....
QA->Access method is used for obtaining a record from a cassette tape is _____.....
QA->The snatch Sc the clean and jerk are two competitions associated with which item in the Olympic Games?....
QA->Which Indian state is the largest manufacturer of passenger cars, two wheelers, and tractors ?....
MCQ->Which two can be used to create a new Thread? Extend java.lang.Thread and override the run() method. Extend java.lang.Runnable and override the start() method. Implement java.lang.Thread and implement the run() method. Implement java.lang.Runnable and implement the run() method. Implement java.lang.Thread and implement the start() method.....
MCQ->Which two statements are true for any concrete class implementing the java.lang.Runnable interface? You can extend the Runnable interface as long as you override the public run() method. The class must contain a method called run() from which all code for that thread will be initiated. The class must contain an empty public void method named run(). The class must contain a public void method named runnable(). The class definition must include the words implements Threads and contain a method called run(). The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments.....
MCQ->What will be the output of the program? class MyThread extends Thread { MyThread() {} MyThread(Runnable r) {super(r); } public void run() { System.out.print("Inside Thread "); } } class MyRunnable implements Runnable { public void run() { System.out.print(" Inside Runnable"); } } class Test { public static void main(String[] args) { new MyThread().start(); new MyThread(new MyRunnable()).start(); } }....
MCQ->What will be the output of the program? class s implements Runnable { int x, y; public void run() { for(int i = 0; i < 1000; i++) synchronized(this) { x = 12; y = 12; } System.out.print(x + " " + y + " "); } public static void main(String args[]) { s run = new s(); Thread t1 = new Thread(run); Thread t2 = new Thread(run); t1.start(); t2.start(); } }....
MCQ->Which two are valid constructors for Thread? Thread(Runnable r, String name) Thread() Thread(int priority) Thread(Runnable r, ThreadGroup g) Thread(Runnable r, int priority)....
Terms And Service:We do not guarantee the accuracy of available data ..We Provide Information On Public Data.. Please consult an expert before using this data for commercial or personal use
DMCA.com Protection Status Powered By:Omega Web Solutions
© 2002-2017 Omega Education PVT LTD...Privacy | Terms And Conditions