+ 2
Explain please Polymorphism concept using example ?
java, polymorphism
5 Respuestas
+ 4
polymorphism means having different forms.
in java, one object can take up many forms and is achieved using method overloading.
for example method show() and show( int a) are different.
0
Thanks Ashhar
0
please rate my question
0
For example if you have interface Sport and you implement classes Chess and Football.if somewhere in code you call method isGameWithBall() (this method is part of interface Sport) on variable which type is Sport interface how Java knows with which code sholud bind this method call.for method in class Chmetho or for method in class Football?in this scenario java use late binding - in runtime decide which code to call.for programmer point of view this is polymorphism.when you call method but that mehod can call different code in runtime.have a nice day;-)
0
polymorphism is really interesting topic.
let me clear you with a task.
I told you to give my message to 'rajiv' from class 8th, but you don't know 'rajiv' n even no one told you how's he look. than u just go to the 8th class and announce name the boy came up. and you will give him the message, but it didn't work when there are two or more 'rajiv' in same class.
I need to clarify you with extra Attributes or behaviour of 'rajiv' whom I want to pass my message( like what he wear today, or have long hair, height 3.9 ft etc..etc, color, body type or anything else for distinguishing.)
the above example is kind of function overloading type of polymorphism.
there are different methods with same name but accessing exact the one with following description provided at call time).