This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Overriding and overloading

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was going through K&B chapter2: Object Orientation , when i came across this line : " For the exam , be sure you know that overloaded methods can change the return type but overriding methods can do so only within the bounds of co-varient returns" .

My doubt is :how "overriding methods can do so only within the bounds of covarient returns" .? What it actually means ?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it means that the overriding method return type can be one of his subclass return type.
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Covariant just means the overridden method can return a subclass of the return type declared in the parent class (This was introduced in Java 5). Tip: Always use the @Override annotation when you override. It will save you tons of grief.

Original method:


OVERLOAD: "overloaded methods can change return type" (and the method signature must change. This means changing the number of arguments and / or the types)


OVERRIDE: "overridden methods must have the same return type OR covariant return type
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim McGuire wrote:
OVERLOAD: "overloaded methods can change return type"


importantly signature[method name and argument] must be different in case of overloading
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:

Tim McGuire wrote:
OVERLOAD: "overloaded methods can change return type"


importantly signature[method name and argument] must be different in case of overloading



Yow. I overlooked that. I'll edit the original.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic