Skills101
← All practice quizzes

Quiz: C++ Classes and Objects

5 questionsNo time limitPass: 60%+10 XP on first pass

Build classes with private data and public methods, constructors (default, parameterised, initializer lists), destructors, the this pointer, const member functions and static members.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What is the default access level of members in a C++ class?

  2. Question 2

    When does a destructor run?

  3. Question 3

    What does this print?

    #include <iostream>
    using namespace std;
    class A {
    public:
        A() { cout << "A"; }
        ~A() { cout << "a"; }
    };
    int main() {
        A x;
        { A y; }
        cout << "|";
        return 0;
    }
    
  4. Question 4

    What does a const member function promise?

  5. Question 5

    How many copies of a static data member exist for 100 objects?