Why do we override? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why do we override?

31st Aug 2016, 10:08 PM
Abdorrahim tr
Abdorrahim tr - avatar
3 Answers
+ 1
If one class is inherited by another one , we can define the methods of super cls as we wish in the sub cls. This is called override. A main concept of OOP ,Polymorphism.
1st Sep 2016, 3:31 PM
Nimsara
+ 1
because we need to implement diiferent behaviour in the same name of method. it is usually implemented in the class that implements some class to have specific classes
2nd Sep 2016, 5:20 PM
Luis Arce
Luis Arce - avatar
+ 1
usually you overload where a method exist with a defined behavior in a super class which does not fulfill your requirements in the subclass that you are working with. often times you cannot change the super class method since it does another job elsewhere and you cannot rewrite your own method full blown (WET). So you take this super class method, and overload it so that it does what you want employing it properties in your own way.
7th Oct 2016, 6:14 AM
Emmanuel Akinpelu