Difference between Concrete Class and Abstract Class in C++

This C++ program differentiates between the concrete and abstract class. An abstract class is meant to be used as a base class where some or all functions are declared purely virtual and hence can not be instantiated. A concrete class is an ordinary class which has no purely virtual functions and hence can be instantiated.

Here is the source code of the C++ program which differentiates between the concrete and abstract class. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ Program to differentiate between concrete class and abstract class
  3.  */	
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. class Abstract {
  9.     private:
  10.         string info;
  11.     public:
  12.         virtual void printContent() = 0; 
  13. };
  14.  
  15. class Concrete {
  16.     private:
  17.         string info;
  18.     public:
  19.         Concrete(string s) : info(s) { }
  20.         void printContent() {
  21.             cout << "Concrete Object Information\n" << info << endl;
  22.         }
  23. };
  24.  
  25. int main()
  26. {
  27.     /*
  28.      * Abstract a;
  29.      * Error : Abstract Instance Creation Failed
  30.      */
  31.     string s;
  32.  
  33.     s = "Object Creation Date : 23:26 PM 15 Dec 2013";
  34.     Concrete c(s);
  35.     c. printContent();
  36. }

$ a.out
Concrete Object Information
Object Creation Date : 23:26 PM 15 Dec 2013

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.