What is Abstraction in C++ Programming


Abstraction is one of the feature of Object Oriented Programming, where you show only relevant details to the user and hide irrelevant details. Abstraction is used to hide internal details and show only functionalities. Abstracting something means to give names to things, so that the name captures the basic idea of what a function or a whole program does.

The program demonstrates the concept of polymorphism in C++ programming using inheritance and virtual functions.

  • The program defines a base class BANK with two pure virtual functions, debit_credit() and loan(). The class BANK is an abstract class, meaning it cannot be instantiated on its own.
  • Then it defines two derived classes HDFC and IB, which override the debit_credit() and loan() methods to print messages specific to each bank's implementation.
  • In the main() function, a pointer b of type BANK is created and assigned the address of a new HDFC object created using the new keyword.
  • When the debit_credit() and loan() methods are called using the b pointer, the derived class HDFC's implementation of these methods is called, printing the messages "Hdfc Banking Debit Credit" and "HDFC Banking loan 12%" respectively.

Overall, this program demonstrates the use of polymorphism in C++ programming to allow for different implementations of the same methods in different classes, enabling more flexible and extensible object-oriented programming.

Note that the IB class is not used in this program but could be instantiated in a similar way as the HDFC class and its methods called through the b pointer to demonstrate further polymorphism.

Source Code

#include<iostream>
using namespace std;
class BANK
{
public:
    virtual void debit_credit()=0;
    virtual void loan()=0;
};
 
class HDFC:public BANK
{
    public:
    void debit_credit()
    {
        cout<<"Hdfc Banking Debit Credit"<<endl;
    }
 
 
    void loan()
    {
        cout<<"HDFC Banking loan 12%"<<endl;
    }
};
 
class IB:public BANK
{
 public:
    void debit_credit()
    {
        cout<<"Indian Banking Debit Credit"<<endl;
    }
    void loan()
    {
        cout<<"Indian Banking loan 8%"<<endl;
    }
};
int main()
{
    BANK *b= new HDFC();
    b->debit_credit();
    b->loan();
    return 0;
}
 

Output

Hdfc Banking Debit Credit
HDFC Banking loan 12%
To download raw file Click Here

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples