Submitted by c-admin on Wed, 06/05/2019 - 06:33
Which of the following standard Java exception classes extend java.lang.RuntimeException?
Select 4 options
A. java.lang.SecurityException
B. java.lang.ClassCastException
C. java.lang.NullPointerException
D. java.lang.CloneNotSupportedException
E. java.lang.IndexOutOfBoundsException
Submitted by c-admin on Wed, 06/05/2019 - 06:32
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.
Submitted by c-admin on Wed, 06/05/2019 - 06:31
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.
Submitted by c-admin on Wed, 06/05/2019 - 06:26
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
Submitted by c-admin on Wed, 06/05/2019 - 06:20
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.
Pages