Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between extends and override?

What is the difference between

extends(inheritance)

and

override(polymorphism)

?

like image 500
Benny Avatar asked Dec 13 '22 11:12

Benny


2 Answers

Extends: we create a new class(Inherited class) with the features of Existing (class Base class) and some additional features. This comes in picture in case of inheritance.

Example: NokiaBasic Handset. NokiaNSeries(Extends the features of NokiaBasic Handset features)

Overriding: comes to picture when functionality changes in the derived class. We override the functionality of a particular function in a derived class(Dynamic Polymorphism).

Example: All the functionality which NokiaBasicHandset has, are implemented in NokiaNSeries but there is a difference in the way we operate. (Picking a call, sending a message, sharing a file, etc.)

like image 109
Pearl Avatar answered Mar 25 '23 06:03

Pearl


  • Extends is about classes. This keyword represents the process of deriving a subclass from a base class.
  • Overriding is about methods declaration and invocation. It means to define a method in a subclass with the same signature of a method previously declared in its base class.
like image 45
Heisenbug Avatar answered Mar 25 '23 07:03

Heisenbug