File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Overloading" Watch "Overloading" New topic
Author

Overloading

shruti patel
Ranch Hand

Joined: Mar 10, 2008
Posts: 52
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
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.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 ]

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
The Car and Ferrari example shows overriding nicely, but it should read super.start() not super().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading