Objects of a derived class can be treated as an object from the base class.
Is the ability to create identically named members within a number of derived class that can different functionality.
This can be achieved either by using Inheritance or by implementing an interface differently in different classes.

An object of the derived class may be referred to (or cast) as either being a base class type.

To understand polymorphism you need to understand the following
1) inheritance
2) virtual methods - A virtual method can be overridden in an inherited class by using the same name and signature
3) late binding - the method being called is looked up by name at runtime

There are two types of polymorphism

Static or Compile Time Polymorphism

The decision is made at compile time
Method overloading uses this type of polymorphism
and is implemented by more than one method with the same name but different parameters

Dynamic or Run Time Polymorphism

The decision is made at run time
Method overriding uses this type of polymorphism
and allows us to have methods in the base class and the derived class with the same name and same parameters

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext