If a class will serve as a base class, most often the base class data members are

private
protected
public
polymorphic

The correct answer is B. protected.

A base class is a class that is used to create other classes. The data members of a base class are accessible to the derived classes. However, they are not accessible to the objects of the base class itself. This is because the base class data members are declared as protected.

The following are the reasons why base class data members are most often declared as protected:

  • To prevent direct access to the base class data members from the objects of the base class itself. This is done to ensure that the base class data members are not modified accidentally or intentionally.
  • To allow the derived classes to access the base class data members. This is done to allow the derived classes to inherit the properties of the base class.
  • To prevent the base class data members from being accessed by other classes. This is done to ensure that the base class data members are not modified by other classes.

The following are the reasons why the other options are not correct:

  • Option A: Private data members are not accessible to any other class, including the derived classes. This means that the derived classes will not be able to inherit the properties of the base class.
  • Option C: Public data members are accessible to any other class, including the derived classes. This means that the derived classes will be able to modify the base class data members.
  • Option D: Polymorphic data members are not a valid option.
Exit mobile version