CS Week 8 - Inheritance and Polymorphism Flashcards

1
Q

Derived class

A

a class that is derived from another class (base class or superclass)

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

Inheritance

A

the derived class inherits the properties of the base class

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

Declaring a derived class

A

place “:” after derived class name, followed by a member access specifier like “public” and base class name

class DerivedClass:public BaseClass {…};

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

member access

A

Members of a derived class have access to the public members of the base class, but not to the private members of the base class

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

protected
private
public

A

protected - accessible by self and derived classes
private - only accessible by self
public - accessible by anyone

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

specifiers in the class definition

A

public - “public->public, protected->protected” - public members of base are accessible as public members of Derived and protected members of base are accessible as protected members of derived

protected - “public->protected, protected->protected” - public and protected members of base are accessible as protected members of derived

private - “public->private, protected->private” - public and protected member of base are accessible as private members of derived, this is the default if none of these are typed (class derived :base{..};)

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

override

A

When a derived class defines a member function with same name and parameters as a base class function, member function overrides the base class function

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

override vs overloading

A

Overloading has different parameters, derived function does not hide base function
Overriding, all the same

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

hasa vs isa

A

Has-a - object has an object, no inheritance

Is-a - object is a kind of object

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

Polymorphism

A

determining which program behavior to execute depending on data types

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

Compile-time polymorphism

A

when the compiler determines which function to call at compile time

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

Runtime polymorphism

A

when the compiler is unable to determine which function to call at compile time, so the determination is made while the program is running

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

derived/base class pointer conversion

A

where a pointer to a derived class is converted to a pointer to the base class without explicit casting

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

Virtual function

A

member function that may be overridden in a derived class and is used for runtime polymorphism

Declared by prepending the keyword “virtual”, ex virtual string GetDescription() const

At runtime, when a virtual function is called using a pointer, the correct function to call is dynamically determined based on the actual object type to which the pointer or reference refers

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

override

A

keyword -optional - indicate that a virtual function is overridden in a derived class

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

virtual table

A

To implement virtual functions, the compiler creates a virtual table that allows the computer to quickly lookup which function to call at runtime

Table contains an entry for each virtual function with a function pointer that points to the most-derived function that is accessible to each class

Looking up which function to call makes runtime polymorphism slower than compile-time polymorphism

17
Q

Pure virtual function

A

a virtual function that provides no definition in base class and all derived classes must override it

Declared like a virtual function but assigned with 0

virtual string GetHours() const = 0;

18
Q

Abstract base class

A

class that has at least one pure virtual function
Cannot declare as an object

19
Q

Classes

A

a class encapsulates data and behavior to create objects

20
Q

Inheritance

A

allows one class (subclass) to be based on another class (a base class or superclass)

21
Q

Abstract classes

A

a class that guides the design of subclasses but cannot itself be instantiated as an object

22
Q

Pure virtual function

A

not implemented in base class, all derived classes must override the function

virtual type name() = 0;

23
Q

Abstract class

A

cannot be instantiated as an object

Is the superclass for a sub class and specifies how subclasses must be implemented

When class has one or more pure virtual functions

24
Q

Concrete class

A

not abstract, can be instantiated

25
Q

Unified modeling language (UML)

A

a language for software design that uses different types of diagrams to visualize the structure and behavior of program

26
Q

Structural diagram

A

visualizes static elements of software, such as attributes (variables) and operations (functions) used in the program

27
Q

Behavioral diagram

A

visualizes dynamic behavior of software, such as the flow of an algorithm

27
Q

A UML class diagram

A

a structural diagram that can be used to visually model the classes of a computer program, including member variables and functions

27
Q

Project management tools

A

automate the compilation and linking process

28
Q

Make

A

one project management tool that is commonly used on Unix and Linux computer systems

29
Q

makefile

A

to recompile and link a program whenever changes are made to the source or header files

30
Q

Makerules

A

used to specify dependencies between a target file (object files and executable) and a set of prerequisite files that are needed to generate the target file (source and header files)

31
Q

make recipe

A

A make rule can include one or more commands - referred to as make recipe that will be executed in order to generate the target file

32
Q

Enumeration type

A

enum - declared a name for a new type and possible values for that type