Inheritence Flashcards

1
Q

What is the syntax to declare a derived class?

A

class derived_name : access_specifier base_name

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

What are the most important rules of constructor pre-initialization with base classes?

A
  • The call to the base class must be called before any other constructor
  • cannot be called in the class or it just creates and instance inside the class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three modes of inheritence?

A
  • public
  • protected
  • private
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the default mode of inheritence?

A

private

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

What happens to the members of a public base class?

A

The public base-members remain public, and the protected base-members remain protected in the derived class.

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

What happens to the members of a protected base class?

A

Both public and protected base-members become protected in the derived class.

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

What happens to member types in a privately inherited base class?

A

Both public and protected base-members become private in the derived class.

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

What base class members do derived classes have access to?

A

Only public and protected, private is inherited but not directly accessible.

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

How can a derived class access private members of a base class?

A

Through getters/setters, or if the base class friends the derived class.

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

What is the essence of polymorphism?

A

The ability to store a derived class in a bass class and use all the methods of the base class.

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

How is runtime polymorphism achieved in C++?

A

With base class pointers and derived class references. ex:
derived d();
base * b = &d;

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

How do you tell a polymorphic object to use the derived method rather than the base method?

A

Virtual Methods

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

What is the syntax to declare a virtual method?

A

virtual return_type method_name(inputs) {}

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

Where are virtual methods declared?

A

In the base class

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

Given class base with method virtual string print, and class derived with method string print, and object derived d (); base *btod = &d;, what method will btod->print() call?

A

The derived print method.

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

Given class base with method string print, and class derived with method string print, and object derived d (); base *btod = &d;, what method will btod->print() call?

A

The base print method

17
Q

What is dynamic_cast<>()?

A

An operator used to cast data from one type to another.

18
Q

What is the syntax to use dynamic casting?

A

dynamic_cast<new_type> (expression)

19
Q

What is downcasting?

A

Casting a base class pointer to a derived class pointer.

20
Q

What is upcasting?

A

Casting a derived class reference to a base class pointer.

21
Q

What happens if you downcast an object into something that is not the type or cannot hold the object?

A

It returns a nullptr.