educative.io

Why use Abstract method makeSound() if the implementation differs?

In the example mentioned here(https://www.educative.io/module/lesson/object-oriented-programming/gxjmwoJWGpl), I get the point of making move() function in the parent class but why have an abstract function of making sound if the function differs in its implementation?

Hi @Manan_Monga!
Your point is valid. You can use methods with same name without having an abstract method. But, if you consider it in a bigger picture. For example, There are thousands of employees working in an organization and have a method work() for each employee. This become little messy if we don’t have an abstract method. OOP is all about giving your code a formal structure for better understanding. So, these are some conventions you should apply to simplify your work or for some other person looking into your code.

Moreover, there’s a basic use of an abstract class. Abstract class basically allows us to provide default functionality for all the child classes through non-abstract methods . So, when we try to create object of an abstract class user will get error on compilation instead of run-time. So, it is safe to have abstract class.

Hope this answer helps. Thanks!