File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why does this compile? 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 "why does this compile? " Watch "why does this compile? " New topic
Author

why does this compile?

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531


isnt this an illegal way of overriding?
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
oh.....i forgot that....sorry i got it why it compiles...
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97


why the above code gives compile error???
can anyone explain please??
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
because at compile time the compiler knows only about the Hotel class.....compiler thinks you would call Hotel's method whch declares to throw a checked exception....which shoudl be caught....which isnt in your code....so bang ...compile error

clear hai?
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
Ankur is right, you have to handle exception at main by either declaring it or catching it


Sage of The Monstrous Toad of Mount Myoboku
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
Yes its cleared..
then what about the above TryIt class?? why its compilng??
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
there is arule that states that the overriden method in subclass can either decalre less exceptions or no exceptions
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
seems you are new...read the Kathy siera book once
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
k Thanks Ankur.
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
I know the rule ankur.. TryIt class compiles because of at comile time the compiler knows about B class so it is compiling..
am i right???
correct me if i am worng??
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
yup...right..bang on target
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
actually the compiler knows abt b so it isnt compiling
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
Ankur kothari wrote:actually the compiler knows abt b so it isnt compiling


What i said...
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
I know the rule ankur.. TryIt class compiles because of at comile time the compiler knows about B class so it is compiling..
am i right???
correct me if i am worng??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why does this compile?