Mohan Giri said:
Sorry, I don't understand what you are saying. Can you explain it with some other example?????????
Animals need water.
A cat is a animal. A dog is a animal.
When you want to give water to a cat, you don't care that its a cat. You only care that it is an animal and needs water. You also don't care if its a dog. You just give water to an animal.
This is a basic example of polymorphism. You have a cat, but treat it as the more basic animal when giving it water. There are no special cases between giving water to a dog or cat. Either way, water goes in the bowl, which goes on the floor. You don't need to know that the animal is a dog or cat, only that it is an animal.
When you feed either, you treat them differently. Cats get cat food, and dogs get dog food. Cats and dogs are cats and dogs when you need to do something specific to a cat or dog. When you are dealing with something common to animals and general, they are just animals.
When talking about polymorphism, the term polymorphism actualy shouldn't be used. "Selective masking" is a bit more appropriate. If a person is male or female, child or adult, they are still a person. If you need to see if the person should go into the men's or woman's restroom, you only care if they are male or female. You don't care about them being an adult or child. If you want to see if someone can vote, you only look at the adult/child aspect, you don't look at the male/female part.
As far as programming is concerned, polymorphism involves treating different objects as the same type of object sometimes, and their individual selves at others.