0

Why to use abstract???

/*abstract class Animal { int legs = 0; abstract void makeSound(); }*/ class Cat /*extends Animal*/ { public void makeSound() { System.out.println("Meow"); } } public class Program { public static void main(String[] args) { Cat c = new Cat(); c.makeSound(); } }

4th Jan 2017, 7:52 AM
Mohd Kaleem Khan
Mohd Kaleem Khan - avatar
2 Answers
+ 1
The abstract oblige you to make the develop the fucntion makeSound() in any class who implement Animal. It's a way to be sure that all the animal (class cat, dog, fish) have the same function (makeSound).
4th Jan 2017, 8:11 AM
Florian Castelain
Florian Castelain - avatar
0
Object abstraction allows for a kind of a blueprint of a given class of objects. So, in this case, the abstract class animal allows for the blueprint of any given animal, so you can implement a cat that will have animal characteristics.
4th Jan 2017, 1:40 PM
Leon Nascimento
Leon Nascimento - avatar