Recall & Review
beginner
What are data members in a C++ class?
Data members are variables that hold the data or state of an object created from a class. They represent the properties of the object.
Click to reveal answer
beginner
What are member functions in a C++ class?
Member functions are functions defined inside a class that operate on the data members. They define the behavior or actions of the object.Click to reveal answer
intermediate
How do you access data members inside member functions?
Inside member functions, you can directly use data members by their names or use the
this pointer to refer to the current object's data members.Click to reveal answer
intermediate
Can member functions modify data members? Explain.
Yes, member functions can modify data members unless the function is declared as <code>const</code>. Non-const member functions can change the object's state.Click to reveal answer
beginner
What is the difference between
public and private data members?<code>Public</code> data members can be accessed from outside the class, while <code>private</code> data members can only be accessed within the class or by friend functions/classes.Click to reveal answer
Which of the following is a data member in a class?
✗ Incorrect
Data members are variables like
int age;. Functions like void display(); are member functions.What keyword is used to define a member function outside the class?
✗ Incorrect
The scope resolution operator
:: is used to define member functions outside the class.Which access specifier restricts access to data members only within the class?
✗ Incorrect
private members are accessible only inside the class.Can a
const member function modify data members?✗ Incorrect
A
const member function cannot modify normal data members but can modify those declared mutable.How do member functions help in object-oriented programming?
✗ Incorrect
Member functions define what actions or behaviors an object can perform.
Explain what data members and member functions are in a class and how they relate to an object.
Think about how a real-world object has properties and actions.
You got /3 concepts.
Describe the difference between public and private data members and why access control is important.
Consider why some information should be hidden from outside access.
You got /3 concepts.