wood burning stoves 2.0*
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
Author

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


Yours,
Bu.


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,
Bu.
marc weber
Sheriff

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
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Overriden method throwing Exception.
 
Similar Threads
null pointer exception by Integer
Question on K& B chapter 5.
An Exception Problem
Exception handling problem
chapter 5,question-8,(k&b)