Deck 15: Inheritance

Full screen (f)
exit full mode
Question
An object of a derived class can be stored in a base class variable
Use Space or
up arrow
down arrow
to flip the card.
Question
Member functions defined as private in the base class are/are not)inherited in the derived class
Question
A derived class automatically gets all the member variables from the base class.
Question
All member functions in a base class should be listed as virtual functions.
Question
If the member variables in a base class are marked as private,can a derived class directly access those variables?
Question
The derived class may define variables and member functions other than those that are in the base class.
Question
If you use the keyword virtual in a function declaration,you must also use it in the function definition.
Question
The base class has everything that is in the derived class and more
Question
A constructor of the base class is ____ inherited in the derived class is/is not)
Question
When the derived class gets all the member variables from the base class,we say that they are _________ from the base class.
Question
When we derive one class from another class,this is known as ____________
Question
If the member variables of the base class are marked as protected,who can access those variables?
Question
The ability to associate multiple meanings to one function name using dynamic binding is called _________.
Question
Which is more general,the base class or the derive class.
Question
Destructors are not inherited into the derived class.
Question
The assignment operator is inherited from the base class.
Question
If two functions in the same scope)have the same name,but a different function signature,this means that the functions are __________.
Question
The copy constructor from the base class is not inherited into the derived class.
Question
The ifstream class is derived from the __________ class.
Question
The constructor for a class is inherited.
Question
Which of the following are true?

A)constructors of the base class are inherited in the derived class.
B)you may not call the base constructor from the derived class
C)You must define constructors in both the base and derived classes
D)all of the above
E)none of the above
Question
C++ implements polymorphism by waiting until run-time to determine which version of a function to use.This is also known as ______________.
Question
If you define a function in the derived class that has the same function signature as a function in the base class,this is known as

A)overloading
B)redefinition
C)overwriting
D)a syntax error
Question
Using inheritance allows us to

A)eliminate duplicate code
B)make our classes more modular
C)use polymorphism
D)all of the above
E)none of the above
Question
If you have the following class definitions,which of the following is the proper way to construct an object of the derived class?
Class Pet
{
Public:
Pet);
Void printPet);
String getName);
Void setNamestring newName);
Private:
String name;
};
Class Dog:public Pet
{
Public:
Dog);
Void printPet);
Void setTypestring newType);
String getType);
Private:
String type;
};

A)Dog::Dog):Pet),type"MUTT") {
}
B)Dog::Dog) {
Name="Rover";
}
C)Pet::Dog):Pet),type"MUTT") {
}
D)Dog::Pet):Pet),type"MUTT") {
}
Question
Which is the correct way to tell the compiler that the class being declared ChildClass)is derived from the base class BaseClass)?

A)class ChildClass::public BaseClass
B)class ChildClass:public BaseClass
C)class ChildClass childOf public BaseClass
D)class ChildClass derived BaseClass
Question
If the member variables in a base class are private,then

A)they can be directly accessed or changed in the derived class
B)the derived class must use any accesssor or modifier functions from the base class
C)making them private causes a syntax error.
D)you must declare them in the derived class also.
Question
In the derived class definition,you list from the base class

A)all the member functions every time
B)only those member functions that need to be redefined
C)only those member functions that were in the public section
D)only those member functions you want to overload.
Question
A base class may have at most _______ child class derived from it.

A)1
B)2
C)12
D)any number
Question
Another name for the base class is

A)parent class
B)super class
C)ancestor class
D)all of the above
E)none of the above
Question
When deriving a class,you should

A)list only base class functions that will be redefined
B)list all the member functions of the base class
C)make every function a virtual function
D)overload all the base class member functions
Question
A derived class pointer can point to
Question
Which of the following are not true

A)an object of the derived class may be stored in a variable of the base class
B)an object of the base class may be stored in a variable of the derived class
C)an object of a derived class that is derived from another class that is derived from a third class can be stored in a variable of the third class.
D)all of the above
E)none of the above
Question
If a base class has a public member function,and the derived class has a member function with the same name,but with a different parameter list,this function is said to be

A)overloaded
B)redefined
C)overwritten
D)a syntax error
Question
If a base class has declared a function to be a virtual function,then does the derived class need to include the word virtual also?
Question
If a base class has public member functions that are not listed by a derived class,then these functions

A)are not available to the derived class
B)are inherited unchanged in the derived class
C)are private to the derived class
D)do not exist in the derived class
Question
A base class pointer variable can point to
Question
What is another name for a child class?

A)derived class
B)sub class
C)descendent class
D)all of the above
E)none of the above
Question
Using virtual functions is also known as _______ the functions
Question
Give a base class with at least one public member function,how many classes can redefine that member function?

A)1
B)0
C)all of them
D)none of the above
Question
Which of the following should be virtual if a base class uses dynamic memory allocation?

A)the constructor
B)the copy constructor
C)the print function
D)the destructor
Question
In order to tell the compiler to wait to decide which version of a function to use,you must precede the function declaration in the base class with the keyword

A)operator
B)friend
C)virtual
D)void
Question
Which of the following would correctly call the base class BaseClass)assignment operator from the derived class DerivedClass)assignment operator?
DerivedClass& DerivedClass::operator =const DerivedClass& rightSide)
{
//what goes here?
}

A)BaseClass::operator=rightSide);
B)leftSide=rightSide;
C)rightSide=BaseClass.rightSide;
D)DerivedClass::rightSide=BaseClass::rightSide;
Question
Polymorphism refers to

A)the ability to assign multiple meanings to one function name.
B)overriding base class functions.
C)overloading functions
D)none of the above
Question
If you have a copy constructor in the base class,but do not have a copy constructor for the derived class,then

A)you will have a syntax error
B)a copy constructor for the derived class is automatically created for you
C)you can not use pointer variables
D)the default constructor is used
Question
Given a class A that derives from a class B that derives from a class C,when an object of class A goes out of scope,in which order are the destructors called?

A)C,B,then A
B)A,B,then C
C)unable to determine
D)depends on how the code is written for the destructors
Question
If a derived class Class2)has redefined a function from the base class Class 1),how can that derived function call the base class function if the function declaration is as follows?
Void print );

A):public Class1::print );
B)Class1 :: print );
C)print );
D)all of the above.
Question
You should make a function a virtual function if

A)every class that is derived from this class use all the member functions from this class.
B)every class that is derived from this class needs to re-define this function.
C)that function is an operator
D)only in the derived classes
Question
Given the following classes and code,what is the output of the last statement shown?
Class Pet
{
Public:
Virtual void print);
String name;
Private:
};
Class Dog: public Pet
{
Public:
Void print);
String breed;
};
Void Pet::print)
{
Cout << "My name is " << name;
}
Void Dog::print)
{
Pet::print);
Cout << ",and my breed is a "<< breed << endl;
}
Pet pPtr;
Dog dPtr;
DPtr->name= "Rover";
DPtr->breed="Weiner";
PPtr= dPtr;
PPtr->print);

A)My name is Rover,and my breed is a Weiner
B)My name is Rover
C),and my breed is a Weiner
D)nothing
Question
Given the following classes and code,what is the output of the last statement shown?
Class Pet
{
Public:
Virtual void print);
String name;
Private:
};
Class Dog: public Pet
{
Public:
Void print);
String breed;
};
Void Pet::print)
{
Cout << "My name is " << name;
}
Void Dog::print)
{
Pet::print);
Cout << ",and my breed is a "<< breed << endl;
}
Pet* pPtr;
Dog* dPtr=new Dog;
DPtr->name= "Rover";
DPtr->breed="Weiner";
PPtr= dPtr;
PPtr->print);

A)My name is Rover,and my breed is a Weiner
B)My name is Rover
C),and my breed is a Weiner
D)nothing
Question
If a base class has a non-virtual member function named print,and a pointer variable of that class is pointing to a derived object,then the code ptr->print ); calls

A)the base class print function
B)the derived print function
C)both the derived and base print functions
D)it causes a run-time error
Question
If a base class has a virtual function named print,and a pointer variable of that class is pointing to a derived object,then the code ptr->print ); calls

A)the base class print function
B)the derived print function
C)both the derived and base print functions
D)it causes a run-time error
Question
Given the following simplified classes,
Class Pet
{
Public:
Virtual void print);
String name;
Private:
};
Class Dog: public Pet
{
Public:
Void print);
String breed;
};
Dog vDog;
Pet vPet;
VDog.name="rover";
VDog.breed = "Collie";
Which of the following statements are not legal?

A)vPet=vDog; cout << vDog.name;
B)vPet=vDog; cout << vDog.breed;
C)vPet=vDog; cout << vPet.name;
D)vPet=vDog; cout << vPet.breed;
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/53
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 15: Inheritance
1
An object of a derived class can be stored in a base class variable
True
2
Member functions defined as private in the base class are/are not)inherited in the derived class
are not
3
A derived class automatically gets all the member variables from the base class.
True
4
All member functions in a base class should be listed as virtual functions.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
5
If the member variables in a base class are marked as private,can a derived class directly access those variables?
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
6
The derived class may define variables and member functions other than those that are in the base class.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
7
If you use the keyword virtual in a function declaration,you must also use it in the function definition.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
8
The base class has everything that is in the derived class and more
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
9
A constructor of the base class is ____ inherited in the derived class is/is not)
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
10
When the derived class gets all the member variables from the base class,we say that they are _________ from the base class.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
11
When we derive one class from another class,this is known as ____________
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
12
If the member variables of the base class are marked as protected,who can access those variables?
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
13
The ability to associate multiple meanings to one function name using dynamic binding is called _________.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
14
Which is more general,the base class or the derive class.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
15
Destructors are not inherited into the derived class.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
16
The assignment operator is inherited from the base class.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
17
If two functions in the same scope)have the same name,but a different function signature,this means that the functions are __________.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
18
The copy constructor from the base class is not inherited into the derived class.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
19
The ifstream class is derived from the __________ class.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
20
The constructor for a class is inherited.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following are true?

A)constructors of the base class are inherited in the derived class.
B)you may not call the base constructor from the derived class
C)You must define constructors in both the base and derived classes
D)all of the above
E)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
22
C++ implements polymorphism by waiting until run-time to determine which version of a function to use.This is also known as ______________.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
23
If you define a function in the derived class that has the same function signature as a function in the base class,this is known as

A)overloading
B)redefinition
C)overwriting
D)a syntax error
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
24
Using inheritance allows us to

A)eliminate duplicate code
B)make our classes more modular
C)use polymorphism
D)all of the above
E)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
25
If you have the following class definitions,which of the following is the proper way to construct an object of the derived class?
Class Pet
{
Public:
Pet);
Void printPet);
String getName);
Void setNamestring newName);
Private:
String name;
};
Class Dog:public Pet
{
Public:
Dog);
Void printPet);
Void setTypestring newType);
String getType);
Private:
String type;
};

A)Dog::Dog):Pet),type"MUTT") {
}
B)Dog::Dog) {
Name="Rover";
}
C)Pet::Dog):Pet),type"MUTT") {
}
D)Dog::Pet):Pet),type"MUTT") {
}
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
26
Which is the correct way to tell the compiler that the class being declared ChildClass)is derived from the base class BaseClass)?

A)class ChildClass::public BaseClass
B)class ChildClass:public BaseClass
C)class ChildClass childOf public BaseClass
D)class ChildClass derived BaseClass
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
27
If the member variables in a base class are private,then

A)they can be directly accessed or changed in the derived class
B)the derived class must use any accesssor or modifier functions from the base class
C)making them private causes a syntax error.
D)you must declare them in the derived class also.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
28
In the derived class definition,you list from the base class

A)all the member functions every time
B)only those member functions that need to be redefined
C)only those member functions that were in the public section
D)only those member functions you want to overload.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
29
A base class may have at most _______ child class derived from it.

A)1
B)2
C)12
D)any number
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
30
Another name for the base class is

A)parent class
B)super class
C)ancestor class
D)all of the above
E)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
31
When deriving a class,you should

A)list only base class functions that will be redefined
B)list all the member functions of the base class
C)make every function a virtual function
D)overload all the base class member functions
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
32
A derived class pointer can point to
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following are not true

A)an object of the derived class may be stored in a variable of the base class
B)an object of the base class may be stored in a variable of the derived class
C)an object of a derived class that is derived from another class that is derived from a third class can be stored in a variable of the third class.
D)all of the above
E)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
34
If a base class has a public member function,and the derived class has a member function with the same name,but with a different parameter list,this function is said to be

A)overloaded
B)redefined
C)overwritten
D)a syntax error
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
35
If a base class has declared a function to be a virtual function,then does the derived class need to include the word virtual also?
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
36
If a base class has public member functions that are not listed by a derived class,then these functions

A)are not available to the derived class
B)are inherited unchanged in the derived class
C)are private to the derived class
D)do not exist in the derived class
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
37
A base class pointer variable can point to
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
38
What is another name for a child class?

A)derived class
B)sub class
C)descendent class
D)all of the above
E)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
39
Using virtual functions is also known as _______ the functions
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
40
Give a base class with at least one public member function,how many classes can redefine that member function?

A)1
B)0
C)all of them
D)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following should be virtual if a base class uses dynamic memory allocation?

A)the constructor
B)the copy constructor
C)the print function
D)the destructor
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
42
In order to tell the compiler to wait to decide which version of a function to use,you must precede the function declaration in the base class with the keyword

A)operator
B)friend
C)virtual
D)void
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following would correctly call the base class BaseClass)assignment operator from the derived class DerivedClass)assignment operator?
DerivedClass& DerivedClass::operator =const DerivedClass& rightSide)
{
//what goes here?
}

A)BaseClass::operator=rightSide);
B)leftSide=rightSide;
C)rightSide=BaseClass.rightSide;
D)DerivedClass::rightSide=BaseClass::rightSide;
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
44
Polymorphism refers to

A)the ability to assign multiple meanings to one function name.
B)overriding base class functions.
C)overloading functions
D)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
45
If you have a copy constructor in the base class,but do not have a copy constructor for the derived class,then

A)you will have a syntax error
B)a copy constructor for the derived class is automatically created for you
C)you can not use pointer variables
D)the default constructor is used
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
46
Given a class A that derives from a class B that derives from a class C,when an object of class A goes out of scope,in which order are the destructors called?

A)C,B,then A
B)A,B,then C
C)unable to determine
D)depends on how the code is written for the destructors
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
47
If a derived class Class2)has redefined a function from the base class Class 1),how can that derived function call the base class function if the function declaration is as follows?
Void print );

A):public Class1::print );
B)Class1 :: print );
C)print );
D)all of the above.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
48
You should make a function a virtual function if

A)every class that is derived from this class use all the member functions from this class.
B)every class that is derived from this class needs to re-define this function.
C)that function is an operator
D)only in the derived classes
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
49
Given the following classes and code,what is the output of the last statement shown?
Class Pet
{
Public:
Virtual void print);
String name;
Private:
};
Class Dog: public Pet
{
Public:
Void print);
String breed;
};
Void Pet::print)
{
Cout << "My name is " << name;
}
Void Dog::print)
{
Pet::print);
Cout << ",and my breed is a "<< breed << endl;
}
Pet pPtr;
Dog dPtr;
DPtr->name= "Rover";
DPtr->breed="Weiner";
PPtr= dPtr;
PPtr->print);

A)My name is Rover,and my breed is a Weiner
B)My name is Rover
C),and my breed is a Weiner
D)nothing
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
50
Given the following classes and code,what is the output of the last statement shown?
Class Pet
{
Public:
Virtual void print);
String name;
Private:
};
Class Dog: public Pet
{
Public:
Void print);
String breed;
};
Void Pet::print)
{
Cout << "My name is " << name;
}
Void Dog::print)
{
Pet::print);
Cout << ",and my breed is a "<< breed << endl;
}
Pet* pPtr;
Dog* dPtr=new Dog;
DPtr->name= "Rover";
DPtr->breed="Weiner";
PPtr= dPtr;
PPtr->print);

A)My name is Rover,and my breed is a Weiner
B)My name is Rover
C),and my breed is a Weiner
D)nothing
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
51
If a base class has a non-virtual member function named print,and a pointer variable of that class is pointing to a derived object,then the code ptr->print ); calls

A)the base class print function
B)the derived print function
C)both the derived and base print functions
D)it causes a run-time error
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
52
If a base class has a virtual function named print,and a pointer variable of that class is pointing to a derived object,then the code ptr->print ); calls

A)the base class print function
B)the derived print function
C)both the derived and base print functions
D)it causes a run-time error
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
53
Given the following simplified classes,
Class Pet
{
Public:
Virtual void print);
String name;
Private:
};
Class Dog: public Pet
{
Public:
Void print);
String breed;
};
Dog vDog;
Pet vPet;
VDog.name="rover";
VDog.breed = "Collie";
Which of the following statements are not legal?

A)vPet=vDog; cout << vDog.name;
B)vPet=vDog; cout << vDog.breed;
C)vPet=vDog; cout << vPet.name;
D)vPet=vDog; cout << vPet.breed;
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 53 flashcards in this deck.