1.

How can you implement static and dynamic polymorphism in C++?

Answer»

Polymorphism refers to the fact that something exists in multiple forms. Polymorphism, in simple terms, is the ability of a MESSAGE to be displayed in multiple formats. On the basis of the time it takes to resolve the procedure call, it can be characterised in two ways.

  • Static polymorphism means that a FUNCTION's invocation (call) is resolved at compile time. Overloading can be used to accomplish this.
    • Function overloading: Overloading of FUNCTIONS occurs when there are numerous functions with the same name but distinct parameters. Changes in the number of arguments or the kind of arguments can cause functions to become overloaded.
    • Operator overloading: C++ also allows you to overload operators. For example, we can use the string class's operator ('+') to concatenate two strings. This is the addition operator, and its job is to add two operands. So, when the operator '+' is used between integer and string operands, it adds them together, and when it is used between string operands, it concatenates them.
  • Dynamic polymorphism refers to the resolution of a function call at runtime. In C++, it is implemented USING the function Overriding in inheritance.
    • Function overriding: Function overriding, on the other side, comes into the picture when a derived class defines one of the base class's members functions. That base function is asserted to be overridden.


Discussion

No Comment Found