• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism

 
Lisa Wilson
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just beginning to learn Java.Can someone please tell me the difference between overloadind and over riding?.
 
Jared White
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difference between Overloading and Overriding
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Lisa Wilson
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jared and Richard
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic