Below is the code
The Code:
#include
using namespace std;
class Rational {
int num; // numerator
int den; // den
While the other posters have explained how the C++ access specifier work, no one has explained why they work in this way.
Increasing encapsulation is all about minimizing the amount of code which has access to your object internals (i.e. your data members), not the number of objects. If the access specifiers limited access to the internals of other objects within the same class, this would not increase encapsulation.
Encapsulation is important because it means that changing implementation details will affect a minimal amount of code. Increasing encapsulation increases the maintainability of code. It is a build-time, not a runtime concept.