lec 9: c++ programming - classes

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/36

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:15 PM on 4/14/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

37 Terms

1
New cards

What is a class in C++ according to the slides?

An expanded concept of a struct that contains data members and functions.

2
New cards

What is an object?

An instantiation (instance) of a class.

3
New cards

What keyword is used to define a class?

class

4
New cards

What can a class contain?

Data members and member functions/methods.

5
New cards

What do the public methods of a class define?

The interface of the class.

6
New cards

How do you call a public method on an object?

Using the dot operator, like object.method().

7
New cards

What are the three access specifiers mentioned in the slides?

private, public, protected

8
New cards

What is the default access specifier for class members?

private

9
New cards

What does private mean?

Accessible only from within members of the same class.

10
New cards

What does public mean?

Accessible from anywhere the class and its objects are visible.

11
New cards

What does protected mean?

Accessible from the same class and derived classes.

12
New cards

Can outside code directly access private data members?

No.

13
New cards

How should outside code usually work with private data?

Through public methods such as setters and getters.

14
New cards

What does Triangle tr2; create?

An object on the stack.

15
New cards

What does Triangle *tr1 = new Triangle; create?

A pointer on the stack pointing to an object on the heap.

16
New cards

Do different objects of the same class share the same member names?

Yes.

17
New cards

Do different objects of the same class have the same member values?

Not necessarily; each object has its own values.

18
New cards

What happens to stack objects when the function ends?

They are destroyed automatically.

19
New cards

How are heap objects created?

With new.

20
New cards

How are heap objects destroyed?

With delete.

21
New cards

Does C++ automatically garbage collect heap objects?

No.

22
New cards

What is a constructor?

A special function automatically called when an object is created.

23
New cards

What is a constructor used for?

Initializing member variables and setting up the object.

24
New cards

What name does a constructor have?

The same name as the class.

25
New cards

Does a constructor have a return type?

No.

26
New cards

What happens if you do not define a constructor?

A default one is usually implicitly created.

27
New cards

Can a class have more than one constructor?

Yes.

28
New cards

What is a default constructor?

A constructor with no parameters.

29
New cards

What is a parameterized constructor?

A constructor that takes arguments.

30
New cards

What does Point p; call in the example?

The default constructor.

31
New cards

What does Point q(10,20); call?

The constructor with two parameters.

32
New cards

What does Point *r = new Point(); call?

The default constructor on a heap object.

33
New cards

What is a copy constructor?

A constructor that initializes one object from another existing object of the same class.

34
New cards

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.

35
New cards

What is the typical form of a copy constructor parameter?

const ClassName &obj

36
New cards

Why is the copy constructor parameter often const?

So the source object cannot be modified through that parameter.

37
New cards

Why is the copy constructor parameter often a reference?

To avoid making an unnecessary extra copy.