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.
Answer:
To determine the correct statement among the given options in C++, we need to evaluate each one based on C++ programming standards.
Classes cannot have data as protected members.
protected
. The protected
access specifier allows the member to be accessed within its own class and by derived class instances.Structures can have functions as members.
structs
) can have member functions just like classes. The main difference between structs
and classes
in C++ is the default access specifier for members.Class members are public by default.
class
are private
by default. This means they are accessible only within the same class or by friend functions.Structure members are private by default.
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.