Job Interviews OOP Concept

Inheritance VS Polymorphism Top Programming Concept

Written by Techringe

List of Best Programming interviews Questions with Examples. Top OOP(Object Oriented Language) concepts with examples.Difference Between Inheritance and Polymorphism.

Inheritance

Constructors are special class functions which performs initialization of every object

Example

class Account {

public:

float salary = 60000;

};

class Programmer: public Account {  public:

float bonus = 5000;     };       int main(void) {   Programmer p1;   cout<<“Salary: “<<p1.salary<<endl;     cout<<“Bonus: “<<p1.bonus<<endl;      return 0;

}




Polymorphism

Destructor on the other hand is used to destroy the class object

Example

class Shape { protected: int width, height; public:

Shape( int a = 0, int b = 0) { width = a; height = b; } virtual int area()

{ cout << “Parent class area :”

<<endl; return 0; } };

 

About the author

Techringe

techringe.com is Platform which offers Free download latest project source code in java, android, php, html, c# .net, c/c++, iphone, vb, python, jsp, asp .net, all programming lanugage.

Leave a Comment