1/36
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is a class in C++ according to the slides?
An expanded concept of a struct that contains data members and functions.
What is an object?
An instantiation (instance) of a class.
What keyword is used to define a class?
class
What can a class contain?
Data members and member functions/methods.
What do the public methods of a class define?
The interface of the class.
How do you call a public method on an object?
Using the dot operator, like object.method().
What are the three access specifiers mentioned in the slides?
private, public, protected
What is the default access specifier for class members?
private
What does private mean?
Accessible only from within members of the same class.
What does public mean?
Accessible from anywhere the class and its objects are visible.
What does protected mean?
Accessible from the same class and derived classes.
Can outside code directly access private data members?
No.
How should outside code usually work with private data?
Through public methods such as setters and getters.
What does Triangle tr2; create?
An object on the stack.
What does Triangle *tr1 = new Triangle; create?
A pointer on the stack pointing to an object on the heap.
Do different objects of the same class share the same member names?
Yes.
Do different objects of the same class have the same member values?
Not necessarily; each object has its own values.
What happens to stack objects when the function ends?
They are destroyed automatically.
How are heap objects created?
With new.
How are heap objects destroyed?
With delete.
Does C++ automatically garbage collect heap objects?
No.
What is a constructor?
A special function automatically called when an object is created.
What is a constructor used for?
Initializing member variables and setting up the object.
What name does a constructor have?
The same name as the class.
Does a constructor have a return type?
No.
What happens if you do not define a constructor?
A default one is usually implicitly created.
Can a class have more than one constructor?
Yes.
What is a default constructor?
A constructor with no parameters.
What is a parameterized constructor?
A constructor that takes arguments.
What does Point p; call in the example?
The default constructor.
What does Point q(10,20); call?
The constructor with two parameters.
What does Point *r = new Point(); call?
The default constructor on a heap object.
What is a copy constructor?
A constructor that initializes one object from another existing object of the same class.
What can a copy constructor be used for?
Initializing one object from another, copying to pass to a function, or copying to return from a function.
What is the typical form of a copy constructor parameter?
const ClassName &obj
Why is the copy constructor parameter often const?
So the source object cannot be modified through that parameter.
Why is the copy constructor parameter often a reference?
To avoid making an unnecessary extra copy.