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(); } }
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).
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.