// C++ does encapsulation class A { public: A() { index = 0; } // constructor int getIndex() { return index; } // accessor void doIncrement() { index++; } // manipulator private: int index; // hidden data }; main() { A a(); a.doIncrement(); int i = a.getIndex(); // a.index = 0; // ERROR: index isn't visible to non-A code! }