Multiple Choice Question

Quiz Guidelines

 

Multiple Choice Question

QID: 
528

Consider the following method 

public float parseFloat( String s ){ 
  float f = 0.0f;   try{      
f = Float.valueOf( s ).floatValue();   
   return f ;   }  
 catch(NumberFormatException nfe){    
  f = Float.NaN ;     
 return f;   }   
finally{   
   f = 10.0f;     
 return f;   } }

What will it return if the method is called with the input "0.0" ?

Select 1 option 

A. It will not compile. 
B. It will return 10.0 
C. It will return Float.Nan 
D. It will return 0.0 
E. None of the above.

Multiple Choice Question

QID: 
527

A try statement must always have a ............. associated with it.

Select 1 option

A. catch 
B. throws 
C. finally 
D. catch, finally or both 
E. throw 

Multiple Choice Question

QID: 
526

What will be the output of the following program?

class TestClass{
public static void main(String[] args) throws Exception{
try{
amethod();
System.out.println("try");
}
catch(Exception e){
System.out.println("catch");
}
finally {
System.out.println("finally");
}
System.out.println("out");
}
public static void amethod(){ }
}

Select 1 option

A. try finally
B. try finally out
C. try out
D. catch finally out
E. It will not compile because amethod() does not throw any exception.

Multiple Choice Question

QID: 
525

What will be the output of the following class...

class Test{
public static void main(String[] args){
int j = 1;
try{
int i = doIt() / (j = 2);
} catch (Exception e){
System.out.println(" j = " + j);
}
}
public static int doIt() throws Exception { throw new Exception("FORGET }

Select 1 option

A. It will print j = 1;
B. It will print j = 2;
C. The value of j cannot be determined.
D. It will not compile.
E. None of the above.

Multiple Choice Question

QID: 
524

What will be the result of attempting to compile and run the following program?

public class TestClass{
public static void main(String args[]){
Exception e = null;
throw e;
}
}

Select 1 option

A. The code will fail to compile.
B. The program will fail to compile, since it cannot throw a null.
C. The program will compile without error and will throw an Exception when run.
D. The program will compile without error and will throw
              java.lang.NullPointerException when run
E. The program will compile without error and will run and terminate without any output.

Pages