Home » JAVA Programming » Multithreading » Question
  1. 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...");
    }
    }
    }
    1. True
    2. False
    3. Running main thread...
    4. HelloJava
    5. 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.



Your comments will be displayed only after manual approval.