Gari Jain wrote:The compiler error is not because of Exception handling. It is because at compile time compiler doesn't know about the object type, it sees that 'a' is of type 'A' and it cant find a function f() in A
if i put the following:
public static void main(String aasd) throws Exception
then,only Exception occurs
If a method declare that it throws a Exception, then the user/caller should take the responsible to handle that exceptions. So, your foo() method throws exception, so you need to handle it or declare it as re-throwing it in the calling method, in your case, the main() method
mohitkumar gupta wrote:
b.)If i put RuntimeException instead of Exception in throws clause of foo method then,it not necessay to declare throws RuntimeException in main method throws
You don't need to handle the RuntimeExceptions!
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
you should try to format your code consistently (indents, use of curly braces, and so on), AND you should use JavaBeans naming standards for your classes, methods and variables. Otherwise the programmers who work with you might throw you out a window
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)