LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 6

The protected access rule for derived classes Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

Truck derives publicly from Vehicle, which has a protected member fuel_. Inside a Truck member function, which access is allowed?

  • A v.fuel_ where v is a Vehicle&
  • B other.fuel_ where other is a Truck& (and this->fuel_) Correct
  • C Both
  • D Neither
Correct Answer: Option B

Protected members may be accessed only through the derived class's own type; otherwise any class could derive from Vehicle just to modify every Vehicle.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links