File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding

 
suganya raj
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is overriding? How it differ from overloading?

Regards,
Suganya

EasyCalculation
ToFocus
 
Gavin Tranter
Ranch Hand
Posts: 333
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overriding is the concept where a subclass will "re-implement" an inherited method to change the way in which that method works. The overriding method would have the same contract as the original method.

When you over load a method, you are provide alternative versions of the same method, but their contact most differ from each other. This can be seen in the wrapper classes for the primitive types. Can be seen in constructors where a number of constructors exist for a class.

G
 
camilo lopes
Ranch Hand
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
overriding - inheritance is mentioned to it when a subclass whom to be more it specifies with the method of the superclassroom.
overloading - you mention yourself to have metodos with name the same, more with different arguments.




so long!
 
Bob Ruth
Ranch Hand
Posts: 320
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In simple-speak....

1) overriding - you are completely replacing the inherited method within the subclass. When this method name is called using a reference to the new subclass object you get the subclass' version of the method. It MUST have the same parameter list and must return the same type EXCEPT that it MAY return a subclass of the overridden class' return type ( see covariant return)

2) overloading - you are adding an implementation of the superclass' method that deals with a different parameter type, a different parameter list, or a combination of those. Since it is a new method it can change the return type.

(edited to fix typo)
[ August 08, 2007: Message edited by: Bob Ruth ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So are these questions from a test, or from an interview?
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a standard interview question in the basic level.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic