Object Oriented Programming - I (3140705) MCQs

MCQs of Concurrency

Showing 21 to 29 out of 29 Questions
21.
Which will contain the body of the thread?
(a) run();
(b) start();
(c) stop();
(d) main();
Answer:

Option (a)

22.
What will be the output of the following Java code?
    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();        
        }
    }
(a) My Thread
(b) Thread[My Thread,5,main]
(c) Compilation Error
(d) Runtime Error
Answer:

Option (b)

23.
What will be the output of the following Java code?
    class newthread extends Thread 
    {
	Thread t;
	newthread()
        {
	    t = new Thread(this,"My Thread");
	    t.start();
	}
	public void run()
        {
            try
            {
                t.join()   
	        System.out.println(t.getName());
            }
            catch(Exception e)
            {
            System.out.print("Exception");
            }
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }
(a) My Thread
(b) Thread[My Thread,5,main]
(c) Exception
(d) Runtime Error
Answer:

Option (d)

24.
What will be the output of the following Java code?
    class newthread extends Thread
    {
	Thread t;
	newthread()
        {
	    t = new Thread(this,"New Thread");
	    t.start();
	}
	public void run()
        {
	   System.out.println(t.isAlive());
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }
(a) 0
(b) 1
(c) TRUE
(d) FALSE
Answer:

Option (c)

25.
What will be the output of the following Java code?
    class newthread extends Thread
    {
	Thread t1,t2;
	newthread()
        {
	    t1 = new Thread(this,"Thread_1");
	    t2 = new Thread(this,"Thread_2");
	    t1.start();
	    t2.start();
	}
	public void run()
        {
	    t2.setPriority(Thread.MAX_PRIORITY);	
	    System.out.print(t1.equals(t2));
        }    
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }
(a) TRUE
(b) FALSE
(c) truetrue
(d) falsefalse
Answer:

Option (d)

26.
What will be the output of the following Java code?
    class newthread implements Runnable 
    {
	Thread t;
	newthread() 
        {
	    t = new Thread(this,"My Thread");
	    t.start();
	}
	public void run()
        {
	    System.out.println(t.getName());
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }
(a) My Thread
(b) Thread[My Thread,5,main]
(c) Compilation Error
(d) Runtime Error
Answer:

Option (a)

27.
What will be the output of the following Java code?
    class newthread implements Runnable
    {
	Thread t;
	newthread()
        {
	    t = new Thread(this,"My Thread");
	    t.start();
	}
	public void run()
        {
	    System.out.println(t);
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }
(a) My Thread
(b) Thread[My Thread,5,main]
(c) Compilation Error
(d) Runtime Error
Answer:

Option (b)

28.
What will be the output of the following Java code?
    class newthread implements Runnable
    {
	Thread t;
	newthread()
        {
	    t = new Thread(this,"New Thread");
	    t.start();
	}
	public void run()
        {
	    t.setPriority(Thread.MAX_PRIORITY);	
            System.out.println(t);
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }
(a) Thread[New Thread,0,main]
(b) Thread[New Thread,1,main]
(c) Thread[New Thread,5,main]
(d) Thread[New Thread,10,main]
Answer:

Option (d)

29.
What will be the output of the following Java program?
    class newthread extends Thread
    {
	Thread t;
	String name;
	newthread(String threadname)
        {
	    name = threadname;
	    t = new Thread(this,name);
	    t.start();
	}
	public void run()
        {
        }
 
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
	    newthread obj1 = 	 new newthread("one");
	    newthread obj2 =	 new newthread("two");
            try
            {
                Thread.sleep(1000);	
                System.out.print(obj1.t.isAlive());
            }
            catch(InterruptedException e)
            {
	    System.out.print("Main thread interrupted");
            }
        }
    }
(a) TRUE
(b) FALSE
(c) Main thread interrupted
(d) None of the mentioned
Answer:

Option (b)

Showing 21 to 29 out of 29 Questions