Which of the following statements about the struct and class keywords is true?
- Only structs can have member functions
- Structs are always public, and classes are always private
- Both can have member functions, but default access is different
- Classes support inheritance, structs don't
Both struct and class in C++ can have member functions, data members, and can support inheritance. The primary difference is the default access level: members of a struct are public by default, whereas members of a class are private. Other functionalities between them are essentially identical.
Loading...
Related Quiz
- In situations where the argument should not be modified, passing by _______ is preferable to ensure the original data remains unaltered.
- Which keyword is used to define a function in C++?
- What implications does the "Rule of Three" have in C++ class design?
- What is a potential risk of using recursion?
- How does the return statement interact with constructors or destructors in C++?