This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "overriding" Watch "overriding" New topic
Author

overriding

suganya raj
Greenhorn

Joined: Aug 08, 2007
Posts: 10
Hi,

What is overriding? How it differ from overloading?

Regards,
Suganya

EasyCalculation
ToFocus
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
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

Joined: Aug 08, 2007
Posts: 202
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!


Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
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 ]

------------------------
Bob
SCJP - 86% - June 11, 2009
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

So are these questions from a test, or from an interview?


[Jess in Action][AskingGoodQuestions]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Looks like a standard interview question in the basic level.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding
 
Similar Threads
Polymorphism
"overload the method"question required
overriding and polymorphism
Typical Overriding and Overloading Examples
How main in superclass is called from subclass