Java Programming and Technical Programming

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

Read Solution (Total 1)

Java Other Question

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
Which of the given fact(s) are true with respect to the blocks and order of execution of blocks in "Exceptions"?

A. The try block can be followed by finally block and then followed by the catch blocks
B. One or more catch blocks which are exception handlers are placed immediately after the try block
C. Catch block has an argument which can accept an argument of any exception type and it is the name of a class that inherits from the Throwable class
D. The finally block always executes when the try block exits or when an exception occurs
E. The finally block is not executed when there is a return statement in the try block