In the context of encapsulation, how does C++ handle data hiding differently from other programming languages?
- By using namespaces exclusively.
- By disallowing external access to data completely.
- Through the use of private and protected access specifiers only.
- By mandatory encapsulation for all classes.
C++ supports data hiding primarily through the use of private and protected access specifiers. Private members are strictly inaccessible from outside the class, while protected members are accessible in derived classes. This mechanism is more flexible compared to some languages that might use other strategies.
Loading...
Related Quiz
- The _______ smart pointer in C++ does not allow the pointer to be shared among objects.
- In situations where the argument should not be modified, passing by _______ is preferable to ensure the original data remains unaltered.
- What is a potential risk of using recursion?
- What is the purpose of the modulus operator (%) in C++?
- What is the potential problem with the following loop: while(true) { /* code */ }?