Sail E0 Webinar
Question


What is the output of this program?


class newthread extends Thread {
newthread() {
super("My Thread");
start();
}
public void run() {
System.out.println(this);
}
}
class multithreaded_programing {
public static void main(String args[]) {
new newthread();
}
}
Options:
A .  My Thread
B .  Thread[My Thread,5,main]
C .  Compilation Error
D .  Runtime Error
Answer: Option B

Although we have not created any object of thread class still we can make a thread 

pointing to main method, we can refer it by using this.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[My Thread,5,main]



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers