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 Polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Polymorphism" Watch "Polymorphism" New topic
Author

Polymorphism

Lisa Wilson
Greenhorn

Joined: Jul 20, 2005
Posts: 2
I am just beginning to learn Java.Can someone please tell me the difference between overloadind and over riding?.
Jared White
Greenhorn

Joined: Aug 11, 2004
Posts: 7
Overloading is giving a method a new signature.

Example:
public int add( int i, int j)
public int add( int i, int j, int k)

Both of these methods have the same name "add" but since the parameters are different the add method is now overloaded.

A method is overridden when you redefine a method in a subclass that was previously defined in a superclass.

Example:

public class A{

//returns the correct sum of i + j
public int add(int i, int j){
return i+j;
}
}

public class BadA{

//returns the incorrect sum of i + j
public int add(int i, int j){
return i+j+1;
}
}

The add method in class BadA overrides the add method of class A.

I hope this helps.
Richard Anderson
Ranch Hand

Joined: May 20, 2005
Posts: 61
Difference between Overloading and Overriding


-Rich, SCJP 1.4
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

"Lisa"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Lisa Wilson
Greenhorn

Joined: Jul 20, 2005
Posts: 2
Thanks Jared and Richard
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism