Recall & Review
beginner
What is the basic syntax to define a class in C++?A class in C++ is defined using the <code>class</code> keyword followed by the class name and a pair of curly braces containing members. Example:<br><pre>class MyClass {<br> // members<br>};</pre>Click to reveal answer
beginner
What are the two main sections inside a C++ class for member access?The two main access specifiers are
public: and private:. public members can be accessed from outside the class, while private members can only be accessed from within the class.Click to reveal answer
beginner
How do you declare a member function inside a class?
Inside the class, you declare a member function by specifying its return type, name, and parameters. Example:<br><pre>class MyClass {<br>public:<br> void greet();<br>};</pre>Click to reveal answer
beginner
What is the purpose of the semicolon after the closing brace in a class definition?In C++, the class definition must end with a semicolon <code>;</code>. This tells the compiler that the class definition is complete.Click to reveal answer
beginner
Can you define member variables inside a class? How?
Yes, member variables are defined inside the class body, usually under <code>private:</code> or <code>public:</code>. Example:<br><pre>class MyClass {<br>private:<br> int age;<br>public:<br> int id;<br>};</pre>Click to reveal answer
Which keyword is used to define a class in C++?
✗ Incorrect
The
class keyword is used to define a class in C++.What symbol must appear after the closing brace of a class definition?
✗ Incorrect
A semicolon
; must follow the closing brace of a class definition.Which access specifier allows members to be accessed from outside the class?
✗ Incorrect
public members can be accessed from outside the class.How do you declare a member function inside a class?
✗ Incorrect
Member functions are declared inside the class with their return type, name, and parameters.
Where are member variables usually declared inside a class?
✗ Incorrect
Member variables can be declared inside either
public: or private: sections.Explain the basic syntax of defining a class in C++ and the role of access specifiers.
Think about how you group related data and functions together and control who can see them.
You got /5 concepts.
Describe how to declare member variables and member functions inside a C++ class.
Remember, variables hold data and functions do actions inside the class.
You got /4 concepts.