• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

polymorphism

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
brief polymorphism
what is overloading & overriding?
tell me also about binding.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,
Well ,overloading is like have the same fuction name with differnet set of parameters. eg
void xyz(int,int){}
void xyz(int,String){}
public String xyz(String){return "sandeep";}
here the fuction names are same however the parameter is different. This is a perfect example of overloading.
It should also be noted that the change in method signature does not mean it is overloading. what i mean is
public String xyz(String){return "sandeep";}
protected String xyz(String){return "sandy";}
this is not overloading.
Overridding is like u declare the code in the parent class and write a class which extends the parent class with the same diganture , method name, and the parameter.

------------------
Sandeep Jain
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Overloading : I hope you are familiar with the concept of constructor if yes then you won the game , overloading is nothing, remember in different-fifferent way you are calling your constructor(of the same class), how you are differentiating your one constructor (of the same class) to another constructor(of the same class).
Here key point is just base on the parameter list, return type is optional. Now overloading does not mean only with constructor, you can play, with other methods also. Constructor is also one method, with having the name similar to your class name.

Overriding: When you are talking about the overriding , Only think about inheritance, so if are, then again you won the game, you are theMan.
Remember : you have to be very carefull about these two things because compiler could not understand what's in your mind what you want to do either overloading or overriding. It won't give you any error. Unfortunately you will not get your expected result, then you are in trouble man.
POLYMORPHISM : very interesting thing, Poly mean what " more than one " , don't get upset here, I know you are qualified person, I'm just trying to take you on the road.
POLY ===>> MORE THAN ONE
POLYMORPHISM ===>> Means refering an object MORE THAN ONE (POLY)way .
EXAMPLE: I have a class called Animal(parent class) and subclass is say Dog, can i inherit Dog from Animal, I know you will say yes.When I am inheriting Dog from Animal, it means whatever is available in Animal class I can get in Dog class also right. So do you allow me directly to reffer Dog object by the Animal reference, atleast for the similar behaviour's, your answer is yes because Dog is nothing just inherited version is of Animal.So that's the POLYMORPHISM .
Examle:
class Animal{
void play(){
System.out.println("Animal.play()");
};
void move(){
System.out.println("Animal.move()");
};
}
class Dog extends Animal{
//overriding in play method
void play(){
System.out.println("Dog.play()");
};
void move(){
System.out.println("Dog.move()");
};
void bark(){
System.out.println("Dog.bark()");
};
}
public class TestPolymorphismOverriden{
public static void main(String args[]){
//(Late)Binding because the right object(Dog) will be assigned at run time. to the Animal reference "d".
Animal d = new Dog();
d.play();
d.move();
}
}

Hope it helps.
jaydeep


 
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic