Polymorphism in c++ - C++ PDF

Title Polymorphism in c++ - C++
Author Alex Morwabe
Course Computer Science
Institution Kisii University
Pages 5
File Size 170.3 KB
File Type PDF
Total Downloads 58
Total Views 193

Summary

C++...


Description

https://www.w3schools.com/cpp/cpp_polymorphism.asp https://www.tutorialspoint.com/cplusplus/cpp_polymorphism.htm https://www.geeksforgeeks.org/polymorphism-in-c/ https://www.programiz.com/cpp-programming/polymorphism https://www.guru99.com/cpp-polymorphism.html#2 https://www.javatpoint.com/cpp-polymorphism

C++ Polymorphism Polymorphism Polymorphism is an important concept of object-oriented programming. It simply means more than one form. That is, the same entity (function or operator) behaves differently in different scenarios.

Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance. Like we specified in the previous chapter; Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways. The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. A real-life example of polymorphism, a person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. So, the same person possesses different behavior in different situations. This is called polymorphism. Polymorphism is considered as one of the important features of Object-Oriented Programming.

In C++ polymorphism is mainly divided into two types: 1) Compile time Polymorphism – This is also known as static (or early) binding. 2) Runtime Polymorphism – This is also known as dynamic (or late) binding.

Compile time polymorphism: This type of polymorphism is achieved by function overloading or operator overloading. 

Function Overloading: When there are multiple functions with same name but different parameters then these functions are said to be overloaded. Functions can be overloaded by change in number of arguments or/and change in type of arguments .

https://www.w3schools.com/cpp/cpp_polymorphism.asp https://www.tutorialspoint.com/cplusplus/cpp_polymorphism.htm https://www.geeksforgeeks.org/polymorphism-in-c/ https://www.programiz.com/cpp-programming/polymorphism https://www.guru99.com/cpp-polymorphism.html#2 https://www.javatpoint.com/cpp-polymorphism // C++ program for function overloading

Example 1: #include using namespace std; void test(int i) { cout...


Similar Free PDFs