We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
REVISION ON OOP
polymorphism is a fundamental concept in object-oriented
programming (OOP) that allows objects of different classes to be treated as objects of a common superclass. There are several types of polymorphism. Here are three common ones:
1. Compile-time Polymorphism (Static Binding or Early
Binding):
Compile-time polymorphism is achieved through method
overloading and operator overloading.
Method Overloading: It allows a class to have multiple methods
with the same name but with different parameters. } }
Operator Overloading: It involves defining operators for user-
defined data types. This is not supported in languages like Java, but is in languages like C++.
2. Run-time Polymorphism (Dynamic Binding or Late Binding):
Run-time polymorphism is achieved through method overriding, also
known as dynamic polymorphism.
Method Overriding: It occurs when a subclass provides a specific
implementation of a method that is already provided by one of its parent classes.
Virtual Functions in C++: In C++, you use virtual functions to
achieve run-time polymorphism.
3. Parametric Polymorphism (Generic Programming):
Parametric polymorphism allows a function or a data type to handle values uniformly across a range of types.
Generics in Java and C#: Allows types to be parameterized.
Templates in C++: It's similar to generics in Java and C# but more
powerful due to C++'s template metaprogramming capabilities.
Each type of polymorphism has its own use cases and advantages, and understanding them is crucial for designing flexible and reusable object-oriented systems.