It is a SCJP objective. I kind of forgot about it too. "When overriding a method, the types listed in the overriding method throws clause can be a subset of the types listed in the overridden method throws clause. It can throw fewer or no exceptions."
Assuming that loginUser() and generateReport() are valid methods and have no problems, which of the following statements about these servlets are true?
Select 1 correct option.
1. LoginServlet.java won't compile.
2. ReportServlet.java won't compile.
3. LoginServlet will throw an exception at runtime.
4. ReportServlet will throw an exception at runtime.
5. Both will compile and run without any problems.
The answer is pretty simple that 2. ReportServlet.java won't compile as getAttribute should be typecast to (String) BUT in the first impression I just looked at the doPost Signature both of the doPost have different signature so I created a new servlet with the first servlets code inside it and its working fine. So from here my doubt started that If SUN has defined the signature with throws clause then we must use it and if NOT then it must throw some exception.