+ 1

why we use abstract classes ?

abstract class Animal { int legs = 0; abstract void makeSound(); } public class Cat extends Animal{ public void makesound(){ System.out.println("meow"); } } here in above code we can also define seprate method makesound for cat,dog and other animals etc................then why define abstract method and implement all details later

13th Jul 2017, 4:41 AM
Abhishek Gupta®
Abhishek Gupta® - avatar
1 Odpowiedź
+ 2
animals have some common properties that abstract classes can capture succinctly. each animal is different so there is no meaning in making animal class concrete. but for a user, all animals can be same. in case new discovery happens, animal can still capture it.
13th Jul 2017, 5:01 AM
Venkatesh Pitta
Venkatesh Pitta - avatar