Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- public class DemoThread extends Thread{
- public void run(String msg){
- System.out.println("Thread Started: " + msg);
- }
- public static void main(String args[]){
- DemoThread thread = new DemoThread();
- thread.start();
- }
- }
b. Program will compile, but will not run.
c. Program will run and print "Thread Started"
d. Program will run and print nothing.
Answer:
D is the correct choice. There is no compilation or runtime error.Class extends Thread class. However, when start method of thread is called, it calls run method whose signature is,
public void run()
Here, the class has run method, which is overriden method. Hence, there will call run method defined in the Thread class, which does nothing. So D is the correct choice.

Post new comment