+ 4
Why is this topic so difficult to understand?
6 Antworten
0
polymorphism is tough to understand as it needs some exposure or hands on at the basics imho. it's 'poly' - 'morph'. ie multiple ways a single method declaration could take form of. never mind if yet u have not got it. Let me say I have a java file which has Animal class with behavior(method) 'makeSound'. I ask u to create Cat class by extending it. Now u can still create meow method but u feel it's bit out of the line (as it is). so u override the make Sound method in Cat class. now u got a Animal class and Cat class.
Animal animal = new Cat();
we are declaring animal object of Type Animal and assigning a Cat type instance.
ie animal object but cat instance. This is absolutely fine as Cat is an animal (cat extends Animal)
now
animal.makeSound() will print meow.
makeSound method from animal object prints meow as per Cat class makeSound method. single method call but different behavior. polymorphism.
- 1
IKR!
- 1
idk either
- 1
You will understand overtime.
- 1
mitochondria is the powerhouse of the cell
- 1
i understand n o t h i n g