logo

CuriousTab

CuriousTab

Discussion


Home Java Programming Threads Comments

  • Question
  • Which three are methods of the Object class?

    1. notify();
    2. notifyAll();
    3. isInterrupted();
    4. synchronized();
    5. interrupt();
    6. wait(long msecs);
    7. sleep(long msecs);
    8. yield();


  • Options
  • A. 1, 2, 4
  • B. 2, 4, 5
  • C. 1, 2, 6
  • D. 2, 3, 4

  • Correct Answer
  • 1, 2, 6 

    Explanation
    (1), (2), and (6) are correct. They are all related to the list of threads waiting on the specified object.

    (3), (5), (7), and (8) are incorrect answers. The methods isInterrupted() and interrupt() are instance methods of Thread.

    The methods sleep() and yield() are static methods of Thread.

    D is incorrect because synchronized is a keyword and the synchronized() construct is part of the Java language.


    Threads problems


    Search Results


    • 1. Which is valid declaration of a float?

    • Options
    • A. float f = 1F;
    • B. float f = 1.0;
    • C. float f = "1";
    • D. float f = 1.0d;
    • Discuss
    • 2. Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

    • Options
    • A. java.util.SortedMap
    • B. java.util.TreeMap
    • C. java.util.TreeSet
    • D. java.util.Hashtable
    • Discuss
    • 3. Which of the following are Java reserved words?

      1. run
      2. import
      3. default
      4. implement

    • Options
    • A. 1 and 2
    • B. 2 and 3
    • C. 3 and 4
    • D. 2 and 4
    • Discuss
    • 4. Which interface provides the capability to store objects using a key-value pair?

    • Options
    • A. Java.util.Map
    • B. Java.util.Set
    • C. Java.util.List
    • D. Java.util.Collection
    • Discuss
    • 5. What line of code should replace the missing statement to make this program compile?
      /* Missing Statement? */
      public class foo 
      {
          public static void main(String[]args)throws Exception 
          {
              java.io.PrintWriter out = new java.io.PrintWriter(); 
              new java.io.OutputStreamWriter(System.out,true); 
              out.println("Hello"); 
          } 
      }
      

    • Options
    • A. No statement required.
    • B. import java.io.*;
    • C. include java.io.*;
    • D. import java.io.PrintWriter;
    • Discuss
    • 6. Which of the following line of code is suitable to start a thread?
      class X implements Runnable 
      { 
          public static void main(String args[]) 
          {
              /* Missing code? */
          } 
          public void run() {} 
      }
      

    • Options
    • A. Thread t = new Thread(X);
    • B. Thread t = new Thread(X); t.start();
    • C. X run = new X(); Thread t = new Thread(run); t.start();
    • D. Thread t = new Thread(); x.run();
    • Discuss
    • 7. Which three guarantee that a thread will leave the running state?

      1. yield()
      2. wait()
      3. notify()
      4. notifyAll()
      5. sleep(1000)
      6. aLiveThread.join()
      7. Thread.killThread()

    • Options
    • A. 1, 2 and 4
    • B. 2, 5 and 6
    • C. 3, 4 and 7
    • D. 4, 5 and 7
    • Discuss
    • 8. Which two are valid constructors for Thread?

      1. Thread(Runnable r, String name)
      2. Thread()
      3. Thread(int priority)
      4. Thread(Runnable r, ThreadGroup g)
      5. Thread(Runnable r, int priority)

    • Options
    • A. 1 and 3
    • B. 2 and 4
    • C. 1 and 2
    • D. 2 and 5
    • Discuss
    • 9. Which cannot directly cause a thread to stop executing?

    • Options
    • A. Calling the SetPriority() method on a Thread object.
    • B. Calling the wait() method on an object.
    • C. Calling notify() method on an object.
    • D. Calling read() method on an InputStream object.
    • Discuss
    • 10. Which two of the following methods are defined in class Thread?

      1. start()
      2. wait()
      3. notify()
      4. run()
      5. terminate()

    • Options
    • A. 1 and 4
    • B. 2 and 3
    • C. 3 and 4
    • D. 2 and 4
    • Discuss


    Comments

    There are no comments.

Enter a new Comment