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 Overriding and Overloading 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 "Overriding and Overloading" Watch "Overriding and Overloading" New topic
Author

Overriding and Overloading

Natallia Batallia
Greenhorn

Joined: Dec 19, 2009
Posts: 1
Hi to all, Could you please clarify why the first code compile, but the second doesn't.

1.


2.



And what rules applied to this code:

Thanks in advance.
Ali Khalfan
Ranch Hand

Joined: Nov 03, 2007
Posts: 126
when you're overriding a method what is the constraint on the sope?on the type? you can't have it public in the superClass and private in the subclass, for example, also the return type should either be of the same type of a subclass of the return type

imagine in polymorphism what'll happen if you say



if the method say was private within child you should be getting a run-time error, so the compiler won't allow it in the first place because it destroys polymoprphism

Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

In this code, Child's method say(), Overriding Parent's method say(), so there's no error in this code..


In this code, Child's method say(), Overloading Parent's method say(), there's error in this code, because the main rule for overloading method not applied...
the main rule for overloading method is, the parameter list should be different..



In this code, Child's method say(), Overloading Parent's method say(), there's error in this code too, because the main rule for overloading method not applied...


Please correct me if i'm wrong..

Thanks..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Eric Nadar
Greenhorn

Joined: Oct 12, 2012
Posts: 12
I know this is an old thread,but i'am not able to understand! Can someone please help?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding and Overloading