Multiple Choice Question

Quiz Guidelines

 

Multiple Choice Question

QID: 
547

Java's Exception mechanism helps in which of the following ways?

Select 2 options

A. It allows creation of new exceptions that are custom to a particular application domain.
B. It improves code because error handling code is clearly separated from the main program logic. 
C. It enhances the security of the application by reporting errors in the logs.
D. It improves the code because the exception is handled right at the place where it occured.
E. It provides a vast set of standard exceptions that covers all possible exceptions.

Multiple Choice Question

QID: 
546

What will the following code print when run?

public class Test {
    static String s = "";
    public static void m0(int a, int b) {
        s += a;
        m2();
        m1(b);
    }
    public static void m1(int i) {
        s += i;
    }
    public static void m2() {
        throw new NullPointerException("aa");
    }
    public static void m() {
        m0(1, 2);
        m1(3);
    }
    public static void main(String args[]) {
        try {
            m();
        } catch (Exception e) {
        }
        System.out.println(s);
    }
}

Select 1 option

A. 1
B. 12
C. 123
D. 2 
E. It will throw exception at runtime.

Multiple Choice Question

QID: 
545

What can be done to get the following code to compile and run? (Assume that the options are independent of each other.)

public float parseFloat( String s ){
     float f = 0.0f;      // 1
     try{
          f = Float.valueOf( s ).floatValue();    // 2
          return f ;      // 3
     }
     catch(NumberFormatException nfe){
        f = Float.NaN ;    // 4
       return f;     // 5
     }
     finally {
         return f;     // 6
     }
     return f ;    // 7
 }

Select 4 options

A. Remove line 3, 6
B. Remove line 5
C. Remove line 5, 6 
D. Remove line 7
E. Remove line 3, 7

Multiple Choice Question

QID: 
544

Given that SomeException is a checked exception, consider the following code:

//in file A.java
public class A{ 
   protected void m() throws SomeException{} 
}

//in file B.java
public class B extends A{ 
   public void m(){ } 
}

//in file TestClass.java
public class TestClass{
   public static void main(String[] args){
      // insert code here. // 1
   }
}

Which of the following options can be inserted at //1?

Select 1 option

A. B b =  new A();
b.m();
B. A a = new B();
a.m();
C. A a = new B();
( ( B) a ).m(); 
D. Object o = new B();
o.m();
E. None of these.

Multiple Choice Question

QID: 
543

Identify the exceptions that will be received when the following code snippets are executed.

1. int factorial(int n){
       if(n==1) return 1;
      else return n*factorial(n-1);
   }
Assume that it is called with a very large integer.

2. void printMe(Object[] oa){
       for(int i=0; i<=oa.length; i++)
       System.out.println(oa[i]);
    }
Assume that it is called as such: printMe(null);

3. Object m1(){
       return new Object(); 
    }
    void m2(){
       String s = (String) m1();
    }

Select 1 option

A. Class Cast Exception
Array Index out of Bounds Exception
Stack Overflow Error

B. Class Cast Exception
Array Index Out Of Bounds Exception
Security Exception

C. No Exception Will Be Thrown
Security Exception
Will Not Compile
 
D. Stack Over flow Error
NullPointerException
No Exception Will Be Thrown 

E. Stack Over flow Error
Array Index Out Of Bounds Exception
Class Cast Exception

F. Stack Over flow Error
NullPointerException
NullPointerException
 
G. Security Exception
Null Pointer Exception
No Exception Will Be Thrown
 
H. Stack Overflow Error
Null Pointer Exception
Class Cast Exception

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!