Java OCA OCP Practice Question 653

Question

You are writing a set of classes related and have created your own exception hierarchy derived from java.lang.Exception as follows:

mypkg.Exception1 
   +-- mypkg.Exception2,  
          +-- mypkg.Exception3 

You have a MyClass class that has the following method:

long connect (String ipAddr) throws Exception1 

You also want to write another AdvancedMyClass class, derived from "MyClass" which overrides the above mentioned method.

Which of the following are valid declaration of the overriding method?

Select 2 options

A. int connect (String ipAddr) throws Exception2 
B. int connect (String ipAddr) throws Exception1 
C. long connect (String ipAddr) throws Exception3 
D. long connect (String ipAddr) throws Exception 
E. long connect (String str)


Correct Options are  : C E

Note

The overriding method must have same return type in case of primitives.

The choices returning int are not valid.

And the parameter list must be the same.

The name of the parameter does not matter, just the Type is important.

The overriding method can throw a subset of the exception or subclass of the exceptions thrown by the overridden class.

Having no throws clause is also valid since an empty set is a valid subset.




PreviousNext

Related