Object Oriented Programming in Dart: Polymorphism
What is Polymorphism? What are Method Overloading and Method Overriding? What are the real-world examples and Advantages of Polymorphism?

Search for a command to run...
What is Polymorphism? What are Method Overloading and Method Overriding? What are the real-world examples and Advantages of Polymorphism?

No comments yet. Be the first to comment.
This series covers all the important concepts of OOPs in Dart i.e: Classes, Objects, Constructor, Abstraction, Inheritance, Polymorphism, and Encapsulation.
What is Encapsulation in Dart? Real-World Example of Encapsulation. What is `_` (Underscore) in Dart? How to write secure and reliable code?
Lessons from Code, Content, and Consistency

Reliability basics: Outbox pattern + why it matters

Introducing Kafka/Redpanda + move to event-driven workflow

Connect Orders β Inventory (first working service-to-service flow)

Inventory service + gRPC + proto contracts

Many)morph(Form)ism means an object with Many Form. 

You can walk. A Dog can walk. Bird can walk.
A single remote is used to control all kinds of TVs.
In all kinds of electronic items, Switching on and off performs the same operation.
In programming, the operator + performs addition with numbers But performs concatenation when used with Strings.
As you can see, Walking, Remote, Switching On-Off, and Operator + behave differently in different situations. This in a nutshell is called Polymorphism
Let's look at how we can achieve polymorphism via code.
class Abc {
void add(int x, int y) {
print("num addition=" + (a + b));
}
void add(double x, double y) {
print("floating num addition=" + (a + b));
}
String add(String x, String y) {
return (x + y);
}
}
In programming languages like JAVA, there are two types of Polymorphism.
Method Overriding (Run-Time Poly.)
The example we saw above of add() is nothing but an example of Method Overloading.
Let's also take one example of Method Overriding.
getROI().class Bank {
getROI(){
return 0;
}
}
class Bank1 extends Bank {
@override
getROI(){
return 2;
}
}
class Bank2 extends Bank {
@override
getROI(){
return 5;
}
}
class Bank3 extends Bank {
@override
getROI(){
return 9;
}
}
getROI method. This is method overriding.