Which of the following statements is correct in C++? a. Classes cannot have data as protected members. b. Structures can have functions as members. c. Class members are public by default. d. Structure members are private by default

Which of the following statements is correct in C++?

a.

Classes cannot have data as protected members.

b.

Structures can have functions as members.

c.

Class members are public by default.

d.

Structure members are private by default.

Which of the following statements is correct in C++?

Answer:
To determine the correct statement among the given options in C++, we need to evaluate each one based on C++ programming standards.

  1. Classes cannot have data as protected members.

    • This statement is false. In C++, classes can have members that are declared as protected. The protected access specifier allows the member to be accessed within its own class and by derived class instances.
  2. Structures can have functions as members.

    • This statement is true. In C++, structures (structs) can have member functions just like classes. The main difference between structs and classes in C++ is the default access specifier for members.
  3. Class members are public by default.

    • This statement is false. In C++, the members of a class are private by default. This means they are accessible only within the same class or by friend functions.
  4. Structure members are private by default.

    • This statement is false. In C++, the members of a struct are public by default. This is opposite to class where members are private by default.

Final Answer:
The correct statement is:
b. Structures can have functions as members.