Java Programming and Technical Programming Technical

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

Read Solution (Total 2)

Java Other Question

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
What will be the output of the program?

public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}

A. hello throwit caught finally after
B. Compilation fails
C. hello throwit RuntimeException caught after
D. hello throwit caught