ahasusie / job-hunting

0 stars 0 forks source link

C++ #28

Open ahasusie opened 5 years ago

ahasusie commented 5 years ago

Overloading occurs when two or more methods in one class have the same method name but different parameters. Overriding means having two methods with the same method name and parameters.

1) Function Overloading happens in the same class when we declare same functions with different arguments in the same class. Function Overriding is happens in the child class when child class overrides parent class function. 2) In function overloading function signature should be different for all the overloaded functions. In function overriding the signature of both the functions (overriding function and overridden function) should be same. 3) Overloading happens at the compile time thats why it is also known as compile time polymorphism while overriding happens at run time which is why it is known as run time polymorphism. 4) In function overloading we can have any number of overloaded functions. In function overriding we can have only one overriding function in the child class.

ahasusie commented 5 years ago

inheritance


virtual function multiple inheritance

ahasusie commented 5 years ago

Rules of Abstract Class 1) As we have seen that any class that has a pure virtual function is an abstract class. 2) We cannot create the instance of abstract class. For example: If I have written this line Animal obj; in the above program, it would have caused compilation error. 3) We can create pointer and reference of base abstract class points to the instance of child class. For example, this is valid:

Animal *obj = new Dog();
obj->sound();

4) Abstract class can have constructors. 5) If the derived class does not implement the pure virtual function of parent class then the derived class becomes abstract.