samedi 9 mai 2015

Java Core Exam Theory

For the following class what is the correct implementation of the Callable interface?

    class Process implements Callable<List<Set<String>>>{    }

A.  public Future< List<Set<String>>> call() throws Exception
B.  public void call(List<Set<String>> data) throws RuntimeException
C.  public List<Set<String>> call(String data) throws RuntimeException
D.  public  List<Set<String>> call() throws Exception

I've implemented this in Eclipse and the answer is D. What I want to know is, how would I know whether or not the class would throw an Exception or a RuntimeException? Is there some way to differentiate? I know a Runtime exception is an unchecked exception and that an Exception is checked, but is there a hint somewhere in the question to tell me that it's the Exception class? If I didn't implemented this in Eclipse there's no way I would have known that the call method doesn't accept a String parameter therefore it would either be C or D. How should I have known the answer was throws Exception?

Aucun commentaire:

Enregistrer un commentaire