Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the main purpose of inheritance in OOP? [duplicate]

Tags:

oop

What is main purpose of inheritance in OOP? i'm new in programming but I think maybe could be code reuse, are there more purposes or a more important purpose?

like image 675
Joe Avatar asked Sep 06 '25 06:09

Joe


1 Answers

The main purpose of inheritance in Object Orientated Programming (OOP) is to give the user ability to change the behavior of the libraries, without actually changing already working and debugged code.

Changing other people's code always has a risk of introducing bugs because you may not fully understanding how the code works. In OOP, the user inherits the object and implements the behavior changes or new features with his own code, separate from the original code.

This way if there are bugs, the user needs to debug and fix only his own code, which is of course an easier task.

like image 186
johnfound Avatar answered Sep 07 '25 19:09

johnfound