C++ ENCAPSULATION

  • In general, encapsulation is a process of wrapping similar code in one place.
  • In C++, we can bundle data members and functions that operate together inside a single class.

EXAMPLE OF ENCAPSULATION

class Box {
   public:
      double getVolume(void) {
         return length * breadth * height;
      }

   private:
      double length;      // Length of a box
      double breadth;     // Breadth of a box
      double height;      // Height of a box
};