File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriden method throwing Exception. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriden method throwing Exception." Watch "Overriden method throwing Exception." New topic

Overriden method throwing Exception.

m ali
Ranch Hand

Joined: Apr 12, 2007
Posts: 49
Hi Ranchers,

If we run it with cmd arguemnt 0 it will print 0. We are sure that in the above code the overridden getInt() method(Subclass version) is calling. Then why we declare main method throws exception,when subclass getInt() method not throwing any exception. Please anyone explain?

Thanks in advance.
Jesse Custer
Ranch Hand

Joined: Feb 07, 2007
Posts: 45
Decision about wich overridden method will be called is made at runtime. The compiler doesn't know that the variable of type Utils actually contains a Ping. So we are forced to handle the exception or declare it like done here.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

yes, when you say
Ping u1 = new Ping() the code compiles without the "throws".

What's a bit confusing about the code, is that you are refering on the arguments of main. It would be easier to understand when you just say


all events occur in real time
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

and now for something completely different.

Try to post what is here in code tags without code tags to the java ranch:

Ping you,
marc weber

Joined: Aug 31, 2004
Posts: 11343

I cannot divulge that secret.
[ April 17, 2007: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Overriden method throwing Exception.
It's not a secret anymore!