You are developing a software library in C++ that will be used by other developers, and you want to ensure that the internal variables of your classes are not accessible while the methods are. How might encapsulation be implemented to achieve this while providing a clear API?
- Make all variables public and methods private.
- Make all methods and variables private.
- Make variables private and methods public.
- Only use static variables and methods.
Encapsulation is achieved by bundling data (variables) and methods that operate on the data into a single unit (class) and restricting the direct access to some of the object's components. In C++, this is implemented by declaring variables as private and providing public methods (API) to access and manipulate them.
Loading...
Related Quiz
- When an array is passed to a function, it is always passed by _______.
- How does the compiler handle inline function calls?
- What is the potential risk of passing parameters by reference?
- The keyword _______ is used to access the base class’s members in the derived class.
- In what year was the C++17 standard released?