Podcast
Questions and Answers
Which concept allows child classes to use, modify, or replace behaviors defined in their parent classes?
Which concept allows child classes to use, modify, or replace behaviors defined in their parent classes?
- Abstraction
- Encapsulation
- Polymorphism
- Inheritance (correct)
What is the most direct consequence of failing to deallocate dynamically allocated memory when it is no longer needed?
What is the most direct consequence of failing to deallocate dynamically allocated memory when it is no longer needed?
- Stack Overflow
- Memory Leak (correct)
- Compiler Error
- Segmentation Fault
When is a class destructor typically called?
When is a class destructor typically called?
- When the class object goes out of scope or is explicitly deleted (correct)
- When a derived class object is created
- When a new member function is called
- When an object is first created
Which of the following best describes encapsulation?
Which of the following best describes encapsulation?
What is required for a derived class function to override a public member function of its base class?
What is required for a derived class function to override a public member function of its base class?
In a linked list, what two things must each node store?
In a linked list, what two things must each node store?
What is the term for the ability of objects to take on many forms, allowing a single function name or operator to be used with different data types?
What is the term for the ability of objects to take on many forms, allowing a single function name or operator to be used with different data types?
If nodePtr
is a pointer to a node in a linked list and data
is a member of that node, how do you access data
?
If nodePtr
is a pointer to a node in a linked list and data
is a member of that node, how do you access data
?
What is the *
operator commonly called in C++?
What is the *
operator commonly called in C++?
What are the individual elements within a class typically called?
What are the individual elements within a class typically called?
When a class inherits private members from a base class, what is their accessibility in the child class?
When a class inherits private members from a base class, what is their accessibility in the child class?
What is the primary purpose of enums?
What is the primary purpose of enums?
What mechanism is used to ensure member variables of a class are initialized when an object is created?
What mechanism is used to ensure member variables of a class are initialized when an object is created?
If Class A contains an object of Class B, this is known as what kind of relationship?
If Class A contains an object of Class B, this is known as what kind of relationship?
Which preprocessor directives are used to prevent multiple inclusions of a header file?
Which preprocessor directives are used to prevent multiple inclusions of a header file?
Why is the const
keyword used with pass-by-reference parameters?
Why is the const
keyword used with pass-by-reference parameters?
In what scenario would using dynamically allocated arrays be preferred over vectors?
In what scenario would using dynamically allocated arrays be preferred over vectors?
What best describes the role of virtual functions in polymorphism?
What best describes the role of virtual functions in polymorphism?
Consider the following. Parent *ptr = new Child();
What does this allow?
Consider the following. Parent *ptr = new Child();
What does this allow?
What happens when the destructor of a class is automatically called, or when you call delete?
What happens when the destructor of a class is automatically called, or when you call delete?
Flashcards
Child Class Behaviors
Child Class Behaviors
Child classes can add new features, modify existing ones, and reuse inherited behaviors.
Memory Leak
Memory Leak
Memory that is allocated during runtime but never deallocated, leading to wasted memory resources.
Destructor
Destructor
A special member function that deallocates memory occupied by an object when it goes out of scope.
Encapsulation
Encapsulation
Signup and view all the flashcards
Function Overloading
Function Overloading
Signup and view all the flashcards
Linked List Node
Linked List Node
Signup and view all the flashcards
Polymorphism
Polymorphism
Signup and view all the flashcards
Arrow Operator (->) for Pointers
Arrow Operator (->) for Pointers
Signup and view all the flashcards
Dereferencing Operator (*)
Dereferencing Operator (*)
Signup and view all the flashcards
Class Members
Class Members
Signup and view all the flashcards
Private Inheritance
Private Inheritance
Signup and view all the flashcards
Function Overriding
Function Overriding
Signup and view all the flashcards
Enums
Enums
Signup and view all the flashcards
Constructor/Initialization list
Constructor/Initialization list
Signup and view all the flashcards
Has-a (Aggregation) Relationship
Has-a (Aggregation) Relationship
Signup and view all the flashcards
Header Guards (#ifndef, #define, #endif)
Header Guards (#ifndef, #define, #endif)
Signup and view all the flashcards
Study Notes
- Exam 2 will cover chapters 1, 2, 3, 4, 5, 6, 7, 8, 10, 14, and the linked list portion of chapter 17.
- Expect questions from lab materials, including debugging and makefiles.
- An extra presentation on makefiles is available on Blackboard.
- All material in the book and slides from meetings 1-18 is testable.
Fill-in-the-Blanks
- Child classes
extend
,replace
, andreuse
parent class behaviors. - Dynamically allocated memory no longer referenced by a pointer results in a
memory leak
. - The
destructor
deallocates memory used by list nodes when the class object goes out of scope. Encapsulation
is a method of hiding information and abstraction.- The function to overload the <= operator would be named
operator <=
. - Each linked list node stores both data and the
pointer/address
of the next node. Polymorphism
refers to reusing defined objects, potentially modifying them.- To access a "data" member via a pointer to a node, use
nodePtr -> data
, and for objects.
is used to accessdata
. *
is called the dereferencing operator in C++.- Class components are called
members
. - Classes inheriting from another class inherit private properties, but they are not directly accessible by the child class.
- To override a public member function, the derived class's function must have the same name, number, and types of parameters.
Enums
are special variables that let you define sets of named constants.- A
constructor/initialization list
is used to ensure class member variables are initialized. Aggregation
represents ahas-a
relationship.- The preprocessor directives
#ifndef
,#define
, and#endif
prevent multiple inclusions of a header file.
Short Answer
- "Pass by reference" in C++ shares with pointers the ability to modify the original variable. However, references are automatically dereferenced and cannot be null, unlike pointers.
- A variable declared within a
while
loop's control statement scope is limited to thewhile
loop. - Overriding parent functions in derived classes can implemented using Virtual functions, which implement late binding.
- Virtual functions enables a parent class pointer to use child class functions.
- The
const
keyword can be used to prevent modification of the parameter being passed. - Dynamically allocated arrays are useful when the size is known beforehand. Vectors are preferred for dynamically sized containers, despite being more expensive.
True or False
- True, enums generate integer constants that can be named.
- True, access modifiers in a class affect the accessibility of the class's members.
- False, arrays in C++ are passed by value. They are passed by reference/pointer
- False, inheritance creates an is-a relationship
- False, a derived class cannot directly intialize private data, use setters or initialization lists.
- False, an abstract class cannot be instantiated, as abstract objects do not exist.
- False, a class's destructor is called when it goes out of scope, or when
delete
is called. - True, each node in a linked list points to another node or to
NULL
. - False, accessing the last element in a singly-linked list takes the most time if there is no tail.
- Singly linked lists end with
node -> node -> node -> null
. Doubly linked lists arenull node null
.
- Singly linked lists end with
- False, you can free memory in a linked list by iterating and calling
delete
instead of usingdelete[] m_head
. - False, the
->
operator is used to access members via pointers. The.
operator is used for objects. - False, the
?:
operator cannot be overloaded. - False, accessing the nth node in a linked list requires iteration, unlike arrays.
- True, vectors store all their data contiguously in memory.
- False, In the provided class,
bar
is constructed beforesour
due to the order in the initialization list.
Code Evaluation Questions
- The code outputs:
- UMBC CHALLENGE
- CHALLENGE CHALLENGE
- HACKATHON HACKATHON
- Based on the enum
enum foo{A=2, B=5, C=6, D, E=10}
, D's integer value is 7. - The output would be c = 456
- if 3 then 123, if not 3 then 456
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.