1/19
These flashcards cover key concepts related to object-oriented programming in C++, focusing on classes, objects, constructors, destructors, and access specifications.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the cornerstone of C++ programming with regards to data modeling?
The class.
List three advantages of using classes in C++.
Types match program concepts. 2. Concise program structure. 3. Easier code analysis and compiler error detection.
What does data abstraction refer to in the context of classes?
Separating implementation details from essential properties.
What is an object in object-oriented programming?
An instance of a class.
What is a constructor?
A special class function used to initialize objects.
What is a destructor?
A special class function that cleans up when an object goes out of scope.
Describe the purpose of access specifiers in a class.
They control the visibility of class members: public, private, and protected.
What is the difference between a static data member and a non-static data member?
Static data members have one shared instance across all objects, while non-static members have unique copies for each object.
Explain what a const member function does.
It guarantees not to modify any class data members.
What happens when a class with a constructor is defined without a default constructor?
The compiler does not automatically generate a default constructor.
How do you declare a member function in a class?
You declare it inside the class body, specifying return type, name, and parameters.
What is the purpose of member functions in a class?
To access or manipulate the values of class data members.
What generates an error if you attempt to call a method on an uninitialized pointer to an object?
It can cause dereferencing a null pointer.
What is the purpose of the copy constructor?
To create a new object as a copy of an existing object.
What indicates that a member variable is protected in a class?
It is accessible within the class and by derived classes, but not from outside.
Provide an example of an object that has been initialized using a constructor.
Rectangle r5(60,80); initializes a Rectangle object with specific dimensions.
What action is taken to prevent memory leaks in the context of object destruction?
Use destructors to release any dynamically allocated memory.
What does the keyword 'this' refer to in a member function?
It points to the object on which the member function is being invoked.
How do you access a private data member from outside the class?
Through public member functions.
In a class, what does an inline member function mean?
The function's definition is provided inside the class body.