Object Oriented Programing
Object Oriented Programing
Function overloading is a C++ programming feature that allows us to have more than one function
having same name but different parameter list, when I say parameter list, it means the data type and
sequence of the parameters, for example the parameters list of a function myfuncn(int a, float
b) is (int, float) which is different from the function myfuncn(float a, int b) parameter list (float, int).
Function overloading is a compile-time polymorphism.
Now that we know what is parameter list lets see the rules of overloading: we can have following
functions in the same scope.
the parameters should qualify any one or more of the following conditions, they should have
different type, number or sequence of parameters.
For example:
These two functions have different parameter type:
All of the above three cases are valid case of overloading. We can have any number of functions, just
remember that the parameter list should be different.
#include <iostream>
class Addition
public:
return num1+num2;
return num1+num2+num3;
};
int main(void) {
Addition obj;
cout<<obj.sum(20, 15)<<endl;
return 0;
Output:
35
191
The main advantage of function overloading is to the improve the code readability and allows code
reusability.
2B)MAKE THE DIFFERENCE BETWEEN CALL BY VALUE,CALL BY REFERNCE AND CALL BY ADDRESS?
Default arguments of the constructor are those which are provided in the constructor declaration. If
the values are not provided when calling the constructor the constructor uses the default arguments
automatically. An example program to demonstrate the concept default arguments in C++ is shown
below.
WHAT IS INHERITANCEIN C++? EXPLAIN ALL TYPE OF INHERITANCE?
The capability of a class to derive properties and characteristics from another class is
called Inheritance. Inheritance is one of the most important features of Object-Oriented
Programming.
Inheritance is a feature or a process in which, new classes are created from the existing classes. The
new class created is called “derived class” or “child class” and the existing class is known as the “base
class” or “parent class”. The derived class now is said to be inherited from the base class.
When we say derived class inherits the base class, it means, the derived class inherits all the
properties of the base class, without changing the properties of base class and may add new
features to its own.
Types Of Inheritance:-
1. Single inheritance
2. Multilevel inheritance
3. Multiple inheritance
4. Hierarchical inheritance
5. Hybrid inheritance
/* YJ
Athematic operations: + – * / %
Logical operations: && and ||
Relational operations: == != >= <=
Pointer operators: & and *
Memory management operator: new, delete []