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





Question 61.

    what does the following expression return?

         (0.0 == -0.0)
 

  1.  true
  2.  false

Question 62.

     What does the following expression print on the screen?

            System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY));
 

  1.  NaN
  2.  Infinity
  3.  The expression throws a runtime exception - NaN is an illegal argument.

Question 63.

        What does the following expression return

            Math.max(Float.POSITIVE_INFINITY,Double.POSITIVE_INFINITY);
 

  1.  Float.POSITIVE_INFINITY
  2.  Double.POSITIVE_INFINITY
  3.  runtime Exception

Question 64.

    Read the following code carefully.

public class AStringQuestion
{
    static String s1;
    static String s2;

    public static void main(String args[])
    {
         s2 = s1+s2;

        System.out.println(s2);
    }
}


    Attempting to compile and run the code
 

  1. Will cause a compilation error.
  2. Runtime Execption - NullPointerException in the 2nd line of the main method.
  3. Will compile successfully and print nullnull on the screen.
  4. Will compile successfully and print an empty line on the screen.
  5. Will compile successfully and print nothing on the screen.



Question 65.

    Read the code below carefully.

public class AQueryClass
{
    public static synchronized void method1()
    {
        //lots and lots of code here.
     }

    public sychronized void method2()
    {
        //lots of code here too.
    }
}

Assuming that all the code inside the method is legal and cannot be a cause for compilation error -
 
  1. An attempt to compile will cause a compilation error. Static methods cannot be synchronized.
  2. Compilation will be successfull. The Object instantiated will have a lock which has to be gained by Threads calling any of the two methods.
  3. Compilation will be successfull. There will exist a Class wide lock which will have to be gained by the Thread calling method1 and an instance lock for each instance which will have to be gained by the Thread making a call to method2 on the Object instance. The class wide lock and the instance lock being independent of each other.
  4. Compilation will be successfull. There will exist a Class wide lock which will have to be gained by the Thread calling method1 and an instance lock for each instance which will have to be gained by the Thread making a call to method2 on the Object instance. The class wide lock and the instance lock being mutually exclusive.

Question 66.

    Class fields with the following modifiers will not be serialized
 

  1. private
  2. static
  3. transient
  4. protected

Question 67.

    Assume that Cat is a class and String[] args is the argument passed to the public static void main(String args[]) method of the class. The class is executed with the following command line string

c:\somedirectory> java Cat

An expression in the main method is as follows

System.out.println(args.length);
 
 

  1. The above expression will cause a '0' appear on the command line.
  2. Will throw a NullPointerException.
  3. Will a blank line to appear.

Question 68.

    A demon Thread group

  1. has only demon threads.
  2. can have non demon threads.
  3. does not exist after all non demon threads in the group have finished executing.
  4. does not exist after all the threads in the group have finished executing.

Question 69.

Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.
 

  1. True
  2. False

Question 70.

    Read the code below carefully.

import java.io.*;

public class OutOut
{
 public static void main(String args[]) throws IOException
 {
  PrintStream pr = new PrintStream(new FileOutputStream("outfile"));

  System.out = pr;

  System.out.println("Lets see what I see now??");
 }
}

  1. The code causes a compiler error. out is a declared final in System and cannot be assigned to pr.
  2. The code causes a runtime Exception due the assignment to a final variable.
  3. The code compiles and runs success fully.  A file called "outfile" is created and "Lets see what I see now??" is printed in the same.

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