Key Things Flashcards

1
Q

What are the principles of OOP?

A
  • Information / data hiding
  • Encapsulation
  • Abstraction
  • Modularization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Encapsulation goes hand-in-hand with what?
What about modularization?

A

Encapsulation goes hand-in-hand with information hiding.
Modularization with low coupling and high cohesion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the basic elements of a C++ program?

A

Classes, methods, and data members

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are these different:
#define constant
const constant
constexpr constant

A

define constant - preprocessor definition that does a simple replacement during preprocessing and before compiling

const constant - names constant declaration where the programmer commits to not changing a value

constexpr constant - constant expressions evaluated at compile time, allowing them to be places in read-only memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference in visibility between a struct and a class?

A

struct - default public
class - default private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In what ways are things allocated on the heap?

A

By using the malloc() function or using ‘new’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the advantages and disadvantages C++ having no garbage collection?

A

Advantages: performance

Disadvantages: cumbersome, error-prone, memory leaks, painful

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can void pointers be dereferenced using “*”?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Functions must be ___ before they are ____?

A

Functions must be declared before they are called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does C++ allow for pass by reference?

A

By supplying the ‘&’ in front of the parameter:

void Two (int& x) {
x = 2;
cout &laquo_space;x &laquo_space;endl;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is it poor-form to use the ‘declaring namespace’ syntax in a header file?

A

Because it can lead to inadvertently opening up access to namespaces in unanticipated ways, leading to name collisions and other problems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Classes are an expanded concept of what?

A

Structs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are private, public, and protected access specifiers for class members?

A

private - accessible only from within other members of the same class

public - accessible from anywhere where the class and its instantiated objects are visible

protected - accessible from other members of the same class and members of their derived class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between the following two:

ObjectType *obj1;
ObjectType obj2;

A

obj1 is a pointer and therefore not instantiated without calling the ‘new ObjectType’ on it.

obj2 is instantiated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

If an access specifier is not provided when inheriting from a base class, what is the default?

A

private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are public, protected, and private inheritance?

A

public inheritance - all members are inherited with the same access levels as they had in the base class

protected inheritance - all public members in the base class are inherited as protected

private inheritance - all members in the base class are inherited as private

17
Q

What is the difference between having the ‘virtual’ keyword on a function and not having it?

A

If there is a ‘virtual’ keyword attached to a method, then when there is some kind of subtype polymorphism such as:

Person *p;
Student *s = new Student();
s->sayHello();
p = s;
p->sayHello();

When p->sayHello() is executed, it calls the method from the student class, not the person class

If there were to be no ‘virtual’ keyword, then the line p->sayHello() would execute the method from the person class.

18
Q

Where is ‘virtual’ specified?

A

In the header file

19
Q

What does it mean for a derived class to be concrete?

A

All virtual methods are implemented

20
Q

What is a “fat interface”?

A

It has many responsibilities and is unfocused and hard to understand/modify