Site hosted by Angelfire.com: Build your free website today!
Java Quiz



Question 51.

    Read the code below carefully.
 

if( "String".endsWith(""))
    Sytem.out.println("True");
else
    System.out.println("False");
   The code produces
  1. True
  2. False

Question 52.

    Read the code below carefully.
 

if( "String".startsWith(""))
    Sytem.out.println("True");
else
    System.out.println("False");
   The code produces
  1. True
  2. False


 

Question 53.

    Read the code below carefully.
 

    public class TestClass
    {
        public static void main(String Args[])
        {
            StringBuffer sb1 = new StringBuffer("String");
            StringBuffer sb2 = new StringBuffer("String");
            if(sb1.equals(sb2))
            {
                //lots of code
            }
         }
    }
    Is the line marked "lots of code" ever reached?


Question 54.

    Read the code below carefully.
 

public class NiceThreads implements Runnable
{
     public void run()
     {
      while(true)
      {
      }
     }
 

     public static void main(String args[])
     {
          NiceThreads nt1 = new NiceThreads();
          NiceThreads nt2 = new NiceThreads();
          NiceThreads nt3 = new NiceThreads();

          nt1.run();
          nt2.run();
          nt3.run();
     }
}

  1. The code does not compile - "nt2.run() is never reached"
  2. The code compiles and runs 3 non ending non demon threads.
  3. The code compiles but  runs only 1 non ending, non demon thread.

Question 55.

    When does the JVM exit?
 

  1. After the main method returns.
  2. After all the non demons threads created by the application complete.
  3. After all the demon threads created by the application complete
  4. When a thread executes System.exit();
  5. When an uncaught exception is thrown in a non demon thread.
  6. When an uncaught exception is thrown in a demon thread.

Question 56.

    Read the following code, which is a part of a synchronized method of a monitor.
 

public synchronized void someMethod()
{
    //lots of code

    try
    {
        Thread.sleep(500);
    }
    catch(InterruptedException e)
    {
        //do some crap here.
    }
    //more and more code here
}

  1. The code causes compilation error  - sleep  cannot be called inside synchronized methods.
  2. The code causes compilation error - sleep is not a static method of java.lang.Thread
  3. The Thread sleeps for at least 500 milliseconds in this method if not interrupted.
  4. When the thread "goes to sleep" it releases the lock on the object.
  5. The "sleeping" Threads always have the lock on the Object.

Question 57.

     The no-argument constructor provided by the compiler when no constructor is explicitly provided in the code
 

  1. is always public
  2. is always "friendly"
  3. always defaults to the access modifier provided for the class.
  4. depends on the compilation options of javac

Question 58.

    Which of the following is the direct base class of java.awt.AWTEvent.
 

  1. java.lang.Object.
  2. java.util.EventObect



Question 59.

     Interface methods can be declared with the following modifiers

  1. public
  2. none (i.e., no access modifier).
  3. private.
  4. static
  5. native
  6. synchronized.



Question 60.

    Which of the following are true about the class defined inside an interface

  1. it is not possible in the java Laungage.
  2. The class is always public.
  3. The class is always static.
  4. the class methods cannot call the methods declared in the interface.
  5. the class methods can call only the static methods declared in the interface.

If you have any concerns regarding any of the questions in this page, please mail me NOW!