Submitted by c-admin on Wed, 05/29/2019 - 06:28
Which digits and in what order will be printed when the following program is run?
public class TestClass{
public static void main(String args[]){
int k = 0;
try{
int i = 5/k;
}catch (ArithmeticException e){
System.out.println("1");
}catch (RuntimeException e){
System.out.println("2");
return ;
}catch (Exception e){
System.out.println("3");
}finally{
System.out.println("4");
}System.out.println("5");
}
}
Select 1 option
A. The program will print 5.
B. The program will print 1 and 4, in that order.
C. The program will print 1, 2 and 4, in that order.
D. The program will print 1, 4 and 5, in that order.
E. The program will print 1,2, 4 and 5, in that order.
Submitted by c-admin on Wed, 05/29/2019 - 06:24
Identify the exceptions that are usually thrown by the JVM and the exceptions usually thrown by an application.
Select 1 option
A. JVM : IllegalStateException, IllegalArgumentException
Application : ClassCastException, NullPointerException, SecurityException
B. JVM : IllegalStateException, IllegalArgumentException, ClassCastException,
Application : NullPointerException, SecurityException
C. JVM : IllegalStateException, IllegalArgumentException, ClassCastException,NullPointerException
Application : SecurityException
D. JVM : ClassCastException, NullPointerException, SecurityException
Application : IllegalStateException, IllegalArgumentException
E. JVM : ClassCastException, NullPointerException
Application : IllegalStateException, IllegalArgumentException, SecurityException
F. JVM : ClassCastException, NullPointerException, IllegalStateException
Application : IllegalArgumentException, SecurityException
Submitted by c-admin on Wed, 05/29/2019 - 06:21
Consider the following code...
public class TestClass{
class MyException extends Exception {}
public void myMethod() throws XXXX{
throw new MyException();
}
}
What can replace XXXX?
Select 3 options
A. MyException
B. Exception
C. No throws clause is necessary
D. Throwable
E. RuntimeException
Submitted by c-admin on Wed, 05/29/2019 - 06:12
A new Java programmer has written the following method that takes an array of integers and sums up all the integers that are less than 100.
public void processArray(int[] values){
int sum = 0;
int i = 0;
try{
while(values[i]<100){
sum = sum +values[i];
i++;
}
}
catch(Exception e){ }
System.out.println("sum = "+sum);
}
Which of the following are best practices to improve this code?
Select 2 options
A. Use ArrayIndexOutOfBoundsException for the catch argument.
B. Use ArrayIndexOutOfBoundsException for the catch argument and add code in the catch block to log or print the exception.
C. Add code in the catch block to handle the exception.
D. Use flow control to terminate the loop.
Submitted by c-admin on Wed, 05/29/2019 - 06:09
What will be the result of compiling and running the following program?
class NewException extends Exception {}
class AnotherException extends Exception {}
public class ExceptionTest{
public static void main(String[] args) throws Exception{
try{
m2();
}
finally{
m3();
}
catch (NewException e){}
}
public static void m2() throws NewException { throw new NewException(); public static void m3() throws AnotherException{ throw new Another
}
Select 1 option
A. It will compile but will throw AnotherException when run.
B. It will compile but will throw NewException when run.
C. It will compile and run without throwing any exceptions.
D. It will not compile.
E. None of the above.
Pages