POLYMORPHISM – Object-Oriented Programming (OOP) TRB CSI › Programming with C++ › polymorphism

POLYMORPHISM – Object-Oriented Programming (OOP)

Polymorphism என்ற வார்த்தை: Poly = Many Morph = Forms அதனால்: Polymorphism means many forms. Programming-ல்: ஒரே function name அல்லது interface different situations-ல் different behavior காட்டுவது Polymorphism. தமிழில்: ஒரே பெயர் அல்லது ஒர…

Premium — locked Advanced 31 min 164 cards 52 programs 12 MCQs v2
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

POLYMORPHISM - Object-Oriented Programming (OO……

Premium This card is part of the premium lesson. Unlock
Definition

Polymorphism என்ற வார்த்தை: Poly = Many Morph = Forms அதனால்: Polymorphism means many forms. Programming-ல்: ……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

ஒரு simple example: sound() Animal class-ல் எல்லா animals-க்கும் sound() என்ற operation இர……

Premium This card is part of the premium lesson. Unlock
Real Life Example

ஒரே person different situations-ல் different roles: At Home → Father At College → Tea……

Premium This card is part of the premium lesson. Unlock
Flow

One Function / Interface ↓ Different In……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

area() | |-- Circle | → πr² | |……

Premium This card is part of the premium lesson. Unlock
Explanation
Types of polymorphism

C++-ல் polymorphism இரண்டு மு……

Premium This card is part of the premium lesson. Unlock
Explanation

1. Compile-Time Polymorphism ……

Premium This card is part of the premium lesson. Unlock
Explanation

இதையே: Static Polymorphism Dy……

Premium This card is part of the premium lesson. Unlock

COMPILE-TIME POLYMORPHISM

Explanation

Compile time-லேயே எந்த function execute ஆக வேண்டும் என்பதை com……

Premium This card is part of the premium lesson. Unlock
Explanation

1. Function Overloading 2. Op……

Premium This card is part of the premium lesson. Unlock
Explanation

Program run ஆகும் நேரத்தில் எந்த function execute ஆக வேண்டும் என்பதை determine செய்யும். இதனை: Dyna……

Premium This card is part of the premium lesson. Unlock
Definition

Same function name, but diffe……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

void add(int a, int b) and: void add(int a, int b……

Premium This card is part of the premium lesson. Unlock
Program
Program - function overloading
Explanation

int add(int a, int b) { return a + b……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Explanation

First function: int add(int a, int b) 2 arguments பெறுகிறது. Second: int add(int a, int b, int c) 3 arguments……

Premium This card is part of the premium lesson. Unlock
Explanation
Operator overloading

C++ operators-க்கு user-defined behavior கொடுக்கலாம். +……

Premium This card is part of the premium lesson. Unlock
List

- integers add செய்கிறது.…

Premium This card is part of the premium lesson. Unlock
Explanation

But class objects-க்கும்: obj……

Premium This card is part of the premium lesson. Unlock
Explanation

int value;…

Premium This card is part of the premium lesson. Unlock
Explanation

Number operator+(Number n) { ……

Premium This card is part of the premium lesson. Unlock
Explanation

Number n3 = n1 + n2;…

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock

இங்கே: + operator user-defined objects-க்……

Premium This card is part of the premium lesson. Unlock
Explanation
Run time polymorphism

Runtime polymorphism புரிய முதலில்: Inheri……

Premium This card is part of the premium lesson. Unlock
Explanation
Function overriding

Base class மற்றும் derived class-ல் same functi……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

இங்கே Dog தனது sound() implementation கொடுக்கிறது. இதனை: Function Overriding என்று அழைக்கிறோம். BUT IMPORTANT……

Premium This card is part of the premium lesson. Unlock
Explanation
Virtual function

Virtual function syntax: virtual void sound() { } virtual keyword: Base class ……

Premium This card is part of the premium lesson. Unlock
Program
Program - run time polymorphism
Explanation

Dog d;…

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Explanation

Base class: class Animal contains: virtual void sound() This is virtual function. Derived class: class Dog : ……

Premium This card is part of the premium lesson. Unlock
Dry Run

Animal *ptr ↓ ptr points to Dog object ↓ ptr->sound() ↓ so……

Premium This card is part of the premium lesson. Unlock

WITHOUT VIRTUAL KEYWORD

Program
Consider

Then: Animal *ptr; Dog d;…

Premium This card is part of the premium lesson. Unlock

Output generally: Animal Why? Because base function virtual இல்லை. Bin……

Premium This card is part of the premium lesson. Unlock

So: Without virtual → Base fu……

Premium This card is part of the premium lesson. Unlock
Explanation
Static binding

Compile-time function selection: Static Binding……

Premium This card is part of the premium lesson. Unlock
Explanation
Dynamic binding

Runtime-ல் function selection……

Premium This card is part of the premium lesson. Unlock
Explanation

Actual object type பார்த்து function select செய்யப்படுகிறது. EARLY BINDING vs LATE BINDING Early Binding = Co……

Premium This card is part of the premium lesson. Unlock
Explanation

virtual void area() = 0; }; D……

Premium This card is part of the premium lesson. Unlock
Explanation

Base pointer: Shape *ptr; can……

Premium This card is part of the premium lesson. Unlock
Explanation

virtual void draw() = 0; };…

Premium This card is part of the premium lesson. Unlock
Explanation

Shape *ptr;…

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock

Same pointer: Shape *ptr Different objects: Circle Rectangle Same funct……

Premium This card is part of the premium lesson. Unlock
Explanation
Polymorphic base pointer

முக்கிய concept: A base-class pointe……

Premium This card is part of the premium lesson. Unlock
Explanation

This relationship runtime polymorphism-க்கு foundation. BASE REFERENCE ALSO WOR……

Premium This card is part of the premium lesson. Unlock
Explanation
Override keyword

Modern C++-ல்: void sound() o……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

override compiler-க்கு: "இந்த function base virtual function-……

Premium This card is part of the premium lesson. Unlock
Explanation
Virtual destructor

ஒரு base class polymorphically பயன்படுத……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Why? Suppose: Base *ptr = new Derived; delete ptr; Base destructor virtual இல்லையெ……

Premium This card is part of the premium lesson. Unlock
Explanation
Pure virtual function

Pure virtual function: virtual void display() = 0; இதுவும் virtual func……

Premium This card is part of the premium lesson. Unlock
Real Life Example
Polymorphism in real life

Payment Example Common function: pay() Different payment methods: UPI → UPI payment logic Credit Card → Card ……

Premium This card is part of the premium lesson. Unlock

Flexibility

Explanation

Same interface different obje……

Premium This card is part of the premium lesson. Unlock

Reusability

Explanation

Common base code reusable.…

Premium This card is part of the premium lesson. Unlock

Extensibility

Explanation

New derived class add செய்தாலும்……

Premium This card is part of the premium lesson. Unlock

Maintainability

Explanation

Complex if-else logic குறைக்க……

Premium This card is part of the premium lesson. Unlock

Loose Coupling

Explanation

Code specific derived class மீது heavily depend ஆகாமல் base interface மீது depend செய்யலாம். WITHOUT POLYMORP……

Premium This card is part of the premium lesson. Unlock
Explanation

SIMPLE MEMORY Overloading → Same Name → Different Parameters → Compile Time Overriding → Same Signature → Par……

Premium This card is part of the premium lesson. Unlock
Explanation

[POLYMORPHISM vs ENCAPSULATION] Encapsulation → Wrap data and methods Inher……

Premium This card is part of the premium lesson. Unlock
Important

Polymorphism means many forms. Main idea: One Interface, Many Forms. Two major types: Compile-Time Run-Time C……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 1

Confusing Overloading and Overriding Overloading: void show(int x); void show(double x); Same c……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 2

Thinking Return Type Alone Can Overl……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 3

Forgetting virtual If base function is not virtual: Base *p ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 4

Signature Mismatch Base: virtual void show(int x); Derived: v……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 5

Base Pointer Cannot Access De……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Then: Animal *ptr = &dog; You……

Premium This card is part of the premium lesson. Unlock
Explanation

because bark() is not part of……

Premium This card is part of the premium lesson. Unlock
Remember

POLY = Many MORPH = Forms So: Polymorphism = Many Forms Best memory line: One Name - Many Behavio……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 1

What is polymorphism? Answer: Abilit……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 2

Meaning of polymorphism? Answ……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 3

Types of polymorphism in C++? Ans……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 4

Function overloading belongs ……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 5

Operator overloading belongs ……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 6

Function overriding with virtual……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 7

Another name for compile-time……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 8

Another name for runtime bind……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 9

Which keyword enables runtime……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 10

Can return type alone differe……

Premium This card is part of the premium lesson. Unlock
Interview Point

What is polymorphism? Polymorphism is the ability to use a common interface for different underlying forms or……

Premium This card is part of the premium lesson. Unlock
MCQ

Polymorphism means:…

Premium This card is part of the premium lesson. Unlock
MCQ

Function overloading is:…

Premium This card is part of the premium lesson. Unlock
MCQ

Operator overloading is:…

Premium This card is part of the premium lesson. Unlock
MCQ

Function overriding is mainly……

Premium This card is part of the premium lesson. Unlock
MCQ

Which keyword is used for dyn……

Premium This card is part of the premium lesson. Unlock
MCQ

Static binding occurs at:…

Premium This card is part of the premium lesson. Unlock
MCQ

Dynamic binding occurs at:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which is another name for dyn……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is required for standar……

Premium This card is part of the premium lesson. Unlock
MCQ

Function overloading requires:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which is true?…

Premium This card is part of the premium lesson. Unlock
MCQ

"One interface, many forms" d……

Premium This card is part of the premium lesson. Unlock
Practice

Consider: class Animal { publ……

Premium This card is part of the premium lesson. Unlock

Polymorphism Type = Run-Time ……

Premium This card is part of the premium lesson. Unlock
Summary

POLYMORPHISM | |-- Means Many Forms | |-- One Interface | Many Behaviors | |-- Compile-Time | | | |……

Premium This card is part of the premium lesson. Unlock
Explanation
Short description

Polymorphism என்பது ஒரே function name அல்லது common interface different objects அல்லது different inputs-க்கு ……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program