C++ Chapter 11: Inheritance and Composition

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The 3 basic concepts of Object-Oriented Design

1) Encapsulation 2) Inheritance 3) Polymorphism

Two most common ways to relate classes

1) Inheritance ("is-a" relationship) 2) Composition ("has-a" relationship)

When does a destructor execute?

A class automatically calls its destructor when the class goes out of scope.

dynamic memory space

A memory location that is allocated during execution time.

Since private members of the base class cannot be accessed directly through the derived class, how can private base members be used?

By accessing them through the public member functions of the base class.

What are destructors for?

Destructors deallocate dynamic memory that had been allocated to the objects of a class.

What does a derived class destructor do?

It executes when the derived class goes out of scope, then calls the destructor of its base class.

What does it mean to "Redefine member functions of the base class"?

It means that the derived class can change member functions it inherits in such a way that the functions have the same name and parameters, but different body code.

If a base class function is NOT redefined in a derived class, how can it be accessed by the derived class?

The derived class can just call the function with its name and parameters.

What is the purpose of "protected" members?

Unlike private members, protected members of a base class can be directly accessed by a derived class, but are still inaccessible outside of the class.

What is the difference between function overloading and function redefining in derived classes?

When a derived class defines a function with the same signature as a function in the base class, the function is said to be redefined. If the derived class defines a function with the same name, but a different signature as a function in the base class, the function is overloaded. Both redefining and overloading are legal in derived classes

When a function is overloaded in a derived class, how does one call the original base function for use?

by using the resolution operator (::) and a correct parameter list

If a function is redefined in a derived class, how can you access the base class version of the function?

by using the scope resolution operator (::) Ex. rectangleType::area()

syntax of a derived class

class className: memberAccessSpecifier baseClassName { member list };

Syntax for triggering a base class constructor in a derived constructor

derivedClass::derivedClass(type Param1, type Param2,...) : baseClass( baseParam1, baseParam2, ...)

What is the difference between public and private inheritance?

in public inheritance, the public members of the base class become public members of the derived class. In private inheritance, all members of the base class become private members that cannot be directly accessed by the derived class.

Where must the triggering of the base function constructor occur?

in the heading of the derived class constructor

derived classes

new classes that are created from base classes

composition (aggregation)

one or more members of a class are objects of another class type; a has-a relationship

If no member access specifier is included, then the program defaults to...

private inheritance

Possible values for "memberAccessSpecifier" when declaring a derived class

public private protected

inheritance

the ability to create new classes from existing classes; an is-a relationship

If a derived class has no declared member variables...

then its member variables are those that were declared in the base class.

multiple inheritance

when a derived class is derived from more than one base class


Kaugnay na mga set ng pag-aaral

日本語総まとめN2語彙 第1週 1日目

View Set

Book Notes Ch. 8 - First Contact: Police and Diversionary Measures

View Set

Chap 31 - Animals: The Invertebrates

View Set

assessment of respiratory function chapter 17

View Set

Chapter 42 Circulatory System Mastering Biology

View Set

Organizational Behavior- Chapter 5- Vocab

View Set