Programming Fundamentals 2 - Inheritance/Polymorphism Quiz

Ace your homework & exams now with Quizwiz!

What type of relationship does Private inheritance model?

"Has-a" relationship

What type of relationship does Public inheritance model?

"Is-a" relationship

What is a pure virtual function?

- A virtual function with no function body and assigned with a value zero. - Indicates that a class is an Abstract Base Class

What is an abstract base class (ABC)?

A class that cannot be instantiated (would lead to compiler error), requires at least one pure virtual function. Useful if you want to inherit the base class, but never create a specific instance of it.

What is a constructor initializer list and what are its uses?

A way to call the constructor of the base class in the constructor of an inherited class example: VIP::VIP(string name, int age, string title) : Person(name, age){} - the last piece of this line of code invokes the base class by forwarding received data into the base constructor - if the base class only has a default constructor, you don't need it

What is polymorphism?

A way to change program behavior based on an object's type rather than values - allows for the writing of generic code and reduces or type-dependent code

What names do we use for two classes involved in inheritance?

Base class: original class with variables and functions to pass on Derived Class: inherits the members and functions from the base (also called parent and child class)

What concept is similar to Private inheritance?

Containment (classes that contain instance(s) of another class)

What is inheritance and why do we use it?

Creating classes that reuse (inherit) functionality from existing classes Used to avoid duplicating code, create efficiency

What is it called when a class inherits from more than one class?

Multiple inheritance example: class NewClass : public Class1, public Class2{};

What is Protected access, and how does it differ from Public or Private access?

Public vars and functions that are inherited become protected in the derived class. Only base class and any classes derived from it can access these. - different from private: private means only base class can access it

What is a virtual function?

functions that can be overridden by derived classes to provide different behaviors

A list of all classes and the class(es) they inherit is sometimes referred to as what?

inheritance tree or hierarchy

What are upcasting and downcasting?

upcasting: an instance of a derived class can be assigned to an instance of a base class downcasting: converts a base type to a derived type; dangerous and often not possible (manager is a person, but a person isn't necessarily a manager)


Related study sets

Chapter 50: Assessment and Management of Patients With Biliary Disorders

View Set

Chapter 4 The Nursing Process and Pharmacology

View Set

Matching Exercise 10.04: Match the type of material used with the situation described.

View Set

PrepU: Ch. 27 Safety, Security and Emergency Preparedness

View Set

Accounting Ethics Chapter 3 HW PROBLEMS

View Set