[go: up one dir, main page]

0% found this document useful (0 votes)
12 views3 pages

CPP Polymorphism Report

The document discusses polymorphism in C++, a key concept in Object-Oriented Programming that allows functions and objects to behave differently based on context. It outlines two types of polymorphism: compile-time (achieved through function and operator overloading) and run-time (achieved using inheritance and virtual functions). The document concludes that polymorphism enhances flexibility and maintainability in programming, making systems easier to extend and modify.

Uploaded by

viceso5578
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

CPP Polymorphism Report

The document discusses polymorphism in C++, a key concept in Object-Oriented Programming that allows functions and objects to behave differently based on context. It outlines two types of polymorphism: compile-time (achieved through function and operator overloading) and run-time (achieved using inheritance and virtual functions). The document concludes that polymorphism enhances flexibility and maintainability in programming, making systems easier to extend and modify.

Uploaded by

viceso5578
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Report on 8085 Microprocessor

1. Introduction

Polymorphism in C++ is one of the core concepts of Object-Oriented Programming (OOP). It allows functions

and objects to behave differently based on the context, improving code flexibility and reusability. The term

'polymorphism' means 'many forms'.

2. Types of Polymorphism

Polymorphism in C++ can be classified into two main types:

1. Compile-time Polymorphism (Static Binding)

2. Run-time Polymorphism (Dynamic Binding)

3. Compile-time Polymorphism

Compile-time polymorphism is achieved through function overloading and operator overloading.

Function Overloading:

Allows multiple functions with the same name but different parameters.

Operator Overloading:

Allows defining custom behavior for operators based on operand types.

4. Run-time Polymorphism

Run-time polymorphism is achieved using inheritance and virtual functions.

Virtual Functions:

Page 1
Report on 8085 Microprocessor

Functions that are declared in a base class and overridden in a derived class.

The function call is resolved at runtime using a virtual table (vtable).

5. Example Code

Example of run-time polymorphism in C++:

class Animal {

public:

virtual void sound() {

cout << "Animal sound" << endl;

};

class Dog : public Animal {

public:

void sound() override {

cout << "Bark" << endl;

};

int main() {

Animal* a;

Dog d;

a = &d;

Page 2
Report on 8085 Microprocessor

a->sound(); // Output: Bark

6. Conclusion

Polymorphism enhances flexibility and maintainability in object-oriented programming. It allows programmers

to design systems that are easier to extend and modify.

Page 3

You might also like