• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method Overriding

 
Vineet Sharma
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody please explain the logic for the following:
"Overriding method must have the same return type as the method it overrides."
Regards
Vineet
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All that is saying is that you can't do this:
In parent class: public int aMethod(int i){return i;}
and then in the subclass try to override it with this:
public String aMethod(int i) {return new String("Hello");}
overridden methods have to return the same type, overloaded methods do not.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic