Java Programming and Technical Programming Technical

Observe the code.

public class Sample {

public static void main(String args[]) {

int i=10,j=0,k;

try {

k=i/j;

}

catch(Exception e) {

System.out.println("Exception");

}

catch(ArithmeticException e) {

System.out.println("Arithmetic exception");

}

}

}

Predict the output.

A. ArithmeticException
B. Compilation Fails
C. Exception
ArithmeticException
D. Runtime exception

Read Solution (Total 2)

Java Other Question

finally block will get executed whether or not an exception occurs. State True or False class ProductNotFoundException extends Exception {

//Some code

}

class Shop {

public void findProduct(int productId) throws ProductNotFoundException {

//some code

throw new ProductNotFoundException();

//some code

}

}

class ABCShop{

public void findProductsList(){

new Shop().findProduct(101);

}

}

Which of the following statement(s) are true for the above code?

A. This code will compile if we add throws ProductNotFoundException in the signature of method findProductsList().
B. This code will compile but returns no output
C. This code will compile if we add a try-catch block in findProductsList().
D. This code will compile if in method findProductsList () returns a list instead of void