Java OCA OCP Practice Question 1094

Question

Which of the following can be inserted into Lion to make this code compile?

Choose all that apply

class Ex1 extends Exception {} 
class Ex2 extends RuntimeException {} 
interface Roar { 
 void roar() throws Ex1; 
} 
class Lion implements Roar {// INSERT CODE HERE 
} 
  • A. public void roar(){}
  • B. public void roar() throws Exception{}
  • C. public void roar() throws Ex1{}
  • D. public void roar() throws IllegalArgumentException{}
  • E. public void roar() throws Ex2{}


A, C, D, E.

Note

The method is allowed to throw no exceptions at all, making option A correct.

It is also allowed to throw runtime exceptions, making options D and E correct.

Option C is also correct since it matches the signature in the interface.




PreviousNext

Related