0

Whats the difference between polymorphism and overidding , and abstraction?

So this is my understanding. Polymorphism is basically when one thing can be implemented differently many times correct? For example, All animals can make a sound, so if i had a main class called animal and passed the following method in the main class : public void Noise(){ System.out.println("Makes Noise"); } And then created 2 more classes called , dog and cat and made then such that they inherit the Animal class and then pass the same Noise method in them with their own implementation : "woof" and "meow". This is polymorphism correct? It seems very similar to abstraction. For abstraction you can also pass a method Noise since its general and then you can simply give the method different implementations according to the specific class. So whats the deal? Sorry for the grammar and sentence structure.

29th Jul 2017, 7:29 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
1 Respuesta
+ 3
You understand what polymorphism is correctly Abstraction is when you declare a method for a class, but don't provide it's body. You leave it to be implemented by subclasses of that class abstract class Animal { public abstract void makeNoise(); } class Dog extends Animal { @Override public void makeNoise { System.out.println("Woof"); } } Note that abstract methods are marked with abstract keyword. Classes that contain such methods are also marked as abstract
29th Jul 2017, 8:03 PM
Eligijus Silkartas
Eligijus Silkartas - avatar