-
What is the output of this program?
class N extends Thread
{
Thread thread;
String Str;
N(String ThreadName)
{
Str = ThreadName;
thread = new Thread(this,Str);
thread.start();
}
public void run()
{
}
}
public class multithreading_EqualsExample
{
public static void main(String args[])
{
N object1 = new N("Hello");
N object2 = new N("Java");
try
{
System.out.print(object1.thread.equals(object2.thread));
}
catch(Exception e)
{
System.out.print("Running main thread...");
}
}
}
-
- True
- False
- Running main thread...
- HelloJava
- None of these
Correct Option: B
Both object1 and object2 have threads with different name that is “Hello” and “Java” hence object1.thread.equals(object2.thread) returns false.