CodesJava

Easy learning with example program codes

CPP Interfaces


Describing the behavior or capabilities of a class is the main purpose served by an interface in CPP. The CPP interface however, does not commit to any particular implementation of a class. To implement an interface in CPP, abstract classes are used. A abstract class is completely different from the concept of data abstraction. A class in CPP is said to be an abstract class if at least one of its function is declared as a pure virtual function (by placing “= 0” in its declaration).

Example:

#include <iostream.h>  
using namespace std;  
class Flower    
{    
public:   
virtual void color()=0;    
};    
class Lily : Flower	 
{    
public:  
void color()    
{    
cout << "White Lily!!" << endl;    
}    
};    
class Rose : Flower	 
{    
public:  
void color()    
{    
cout <<"Red Rose!!" << endl;    
}    
};    
int main( ) {  
Lily lly;  
Rose rse;  
lly.color();    
rse.color();   
return 0;  
}

Output

White Lily!!        
Red Rose!!
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki