File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic


mukhan myrzakulov

Joined: Jan 16, 2008
Posts: 13
Hi, I am confused with POLYMORPHISM in overloaded and overriden methods. So, as I understood, Java doesn't give you polymorphism when you use overloading. For example,

class Animal{}
class Horse extends Animal{}
class TestIt{
public void eat(Animal a){
System.out.println("Animal is eating!!!");
public void eat(Horse h){
System.out.println("Horse is eating!!!");

public static void main(Stirng [] args){
Animal a = new Animal();
Animal h = new Horse();
TestIt t = new TestIt();;// prints "Animal is eating!!!";// prints "Horse is eating!!!"

Can't understand why it does it? Why not to use polymorphism...

Next example:
class Animal{
public void eat(){
System.out.println("Animal is eating");

class Horse extends Animal{
public void eat(){
System.out.println("Horse is eating");
public void eat(String food){
System.out.println("Horse is eating " + food);
pulbic class Test{

marc weber

Joined: Aug 31, 2004
Posts: 11343

This is a duplicate.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Polymorphism
jQuery in Action, 3rd edition