Encapsulation in C++ MCQs Exercise II


Ques 1 Encapsulation


How can you access a private member variable of a class from outside the class?
  a) Private members cannot be accessed from outside the class
  b) By using a friend function
  c) By using a member function within the class
  d) By inheriting from the class


a is the correct option





Ques 2 Encapsulation


In C++20, what new feature was introduced to support read-only access to private member variables?
  a) readonly keyword
  b) get accessor method
  c) const keyword
  d) readonly access specifier


c is the correct option





Ques 3 Encapsulation


Which C++20 feature allows you to declare a member function within a class that can be called without creating an object?
  a) Static member function
  b) Friend function
  c) Const member function
  d) Lambda function


a is the correct option