Can any one please explain how to implement polymorphism without inheritance in java.
It would be useful if it is explained starting with what is polymorphism, types of polymorphism and polymosrphism with inheritance and without inheritance.
Polymorphism : Polymorphism is a charactertisic of being able to assign a different behaviour or value in a sub class which was something to declare in a parent class.
Types of Polymorphism : There are two types of polymorphism. One is compile time polymorphism and another is run time polymorphism.
Compile Time Polymorphism : It is method overloading.
Method Overloading : When two or more methods with same name in the same class with different arguments. This is called method overloading.
Run Time Polymorphism : Run Time Polymorphism is done by using inheritance & interface. Run Time Polymorphism is a process in which a call to an overridden method is resolve at run time rather than at compile time. In this process an overridden method is called through the reference variable of a superclass
I disagree, below is what your link says about Composition -
The relationship modeled by composition is often referred to as the "has-a" relationship. In this case a CoffeeCup has Coffee. As you can see from this example, the has-a relationship doesn't mean that the containing object must have a constituent object at all times, but that the containing object may have a constituent object at some time. Therefore the CoffeeCup may at some time contain Coffee, but it need not contain Coffee all the time. (When a CoffeeCup object doesn't contain Coffee, its innerCoffee field is null.) In addition, note that the object contained can change throughout the course of the containing object's life.
Which is not Polymorphism.
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?