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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *