Java Quiz
Question 61.
what does the following expression return?
(0.0 == -0.0)
- true
- false
Question 62.
What does the following expression print on the
screen?
System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY));
- NaN
- Infinity
- 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);
- Float.POSITIVE_INFINITY
- Double.POSITIVE_INFINITY
- 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
- Will cause a compilation error.
- Runtime Execption - NullPointerException in the 2nd line of the main
method.
- Will compile successfully and print nullnull on the screen.
- Will compile successfully and print an empty line on the screen.
- 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 -
- An attempt to compile will cause a compilation error. Static methods
cannot be synchronized.
- Compilation will be successfull. The Object instantiated will have a lock
which has to be gained by Threads calling any of the two methods.
- 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.
- 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
- private
- static
- transient
- 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);
- The above expression will cause a '0' appear on the command line.
- Will throw a NullPointerException.
- Will a blank line to appear.
Question 68.
A demon Thread group
- has only demon threads.
- can have non demon threads.
- does not exist after all non demon threads in the group have finished
executing.
- 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.
- True
- 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??");
} }
- The code causes a compiler error. out is a declared final in
System and cannot be assigned to pr.
- The code causes a runtime Exception due the assignment to a final
variable.
- 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!
|