Multiple Choice Question

Quiz Guidelines

 

QID: 
523
Question: 

Consider the following code:

class A {
public void doA(int k) throws Exception {        // 0
for(int i=0; i< 10; i++) {
if(i == k) throw new Exception("Index of k is "+i);        // 1
}
}
public void doB(boolean f) {       // 2
if(f) {
doA(15); // 3
}
else return;
}
public static void main(String[] args) { // 4
A a = new A();
a.doB(args.length>0); // 5
}
}

Which of the following statements are correct?

Select 1 option

A. This will compile and run without any errors or exception.
B. This will compile if throws Exception is added at line //2
C. This will compile if throws Exception is added at line //4
D. This will compile if throws Exception is added at line //2 as well as //4
E. This will compile if line marked // 1 is enclosed in a try - catch block.

Q&A Set: