• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding and Overloading

 
Natallia Batallia
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Eric Nadar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is an old thread,but i'am not able to understand! Can someone please help?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic