0
0
C++programming~5 mins

Classes and objects in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a class in C++?
A class is a blueprint or template for creating objects. It defines properties (data members) and behaviors (member functions) that the objects created from the class will have.
Click to reveal answer
beginner
What is an object in C++?
An object is an instance of a class. It holds actual values for the properties defined by the class and can use the behaviors (functions) defined in the class.
Click to reveal answer
beginner
How do you define a simple class with one integer property and a function to set it?
Example:
class MyClass {
public:
  int value;
  void setValue(int v) {
    value = v;
  }
};
Click to reveal answer
intermediate
What is the difference between public and private members in a class?
Public members can be accessed from outside the class, while private members can only be accessed from within the class itself.
Click to reveal answer
beginner
How do you create an object of a class and call its member function?
Example:
MyClass obj;  // create object
obj.setValue(10);  // call member function
int x = obj.value;  // access property
Click to reveal answer
What keyword is used to define a class in C++?
Adefine
Bobject
Cstruct
Dclass
Which of the following is true about objects?
AObjects are templates for classes
BObjects are instances of classes
CObjects cannot have functions
DObjects are the same as classes
What access specifier allows members to be accessed outside the class?
Aprivate
Bprotected
Cpublic
Dinternal
How do you call a member function named 'setValue' on an object 'obj'?
Aobj.setValue()
BsetValue.obj()
Cobj->setValue()
Dobj:setValue()
Which of these is NOT a member of a class?
AObjects
BMember functions
CData members
DConstructors
Explain what a class and an object are in your own words.
Think about how a cookie cutter (class) makes cookies (objects).
You got /3 concepts.
    Describe how access specifiers like public and private affect class members.
    Imagine a house with a front door (public) and a locked safe inside (private).
    You got /3 concepts.