This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Overloading  RSS feed

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the purpose of method overriding in Java where we are completely re-defining a inherited method instead why can't we create a new method and define.If the question is very silly please excuse me and do reply
 
Marshal
Posts: 62286
194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it isn't a silly question.

An overridden method allows you to use the same invocation as in the superclass and receive a different result.
 
Ranch Hand
Posts: 2908
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider an Interface , When we implement an interface we have to override the abstract methods , because thats the contract we need to fulfill in order to successfully implement the interface !

Now I`m not much experienced in java , this what I got from my 1 year of experience as per need of overriding !!

1. sometimes a base class defined a very basic operation , and the code which extends it must have to implement the more advance code for that method , like If we consider an base class 'Car', which got start() method



and when we want the class which IS a Car with more specialized functionality , lets say Ferrari ,



Now If we define a new method for start(), then What ll be the use of that Car#start() code , We must concentrate the re usability of the code .

[Thanks for correcting me , Campbell ]
[ August 12, 2008: Message edited by: Sagar Rohankar ]
 
Campbell Ritchie
Marshal
Posts: 62286
194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Car and Ferrari example shows overriding nicely, but it should read super.start() not super().
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!