Deck 10: Understanding Inheritance
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
Match between columns
سؤال
سؤال
سؤال
Match between columns
سؤال
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/53
العب
ملء الشاشة (f)
Deck 10: Understanding Inheritance
1
A(n) ____ is a very specific instance of a class.
A) superclass
B) derived class
C) object
D) child class
A) superclass
B) derived class
C) object
D) child class
C
2
When a class serves as a base class to other classes, all of its members are included when you create an object from a derived class. However, the members of the base class that are ____ are not directly accessible from within the child class functions.
A) public
B) protected
C) private
D) virtual
A) public
B) protected
C) private
D) virtual
C
3
____ data and functions can be accessed only by class functions, or by functions in child classes.
A) public
B) protected
C) private
D) virtual
A) public
B) protected
C) private
D) virtual
B
4
To create a class Customer that derives from the class Person , you should use the following syntax:
Class Customer ____ public Person // public may be replaced
// by another class access
// specifier
{
// other statements go here
};
A) :
B) extends
C) ::
D) ->
Class Customer ____ public Person // public may be replaced
// by another class access
// specifier
{
// other statements go here
};
A) :
B) extends
C) ::
D) ->
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
5
When a class is a base class you are required to define data as protected rather than private .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
6
____ is based on the principle that knowledge of a general category can be applied to more specific objects.
A) Overloading
B) Inheritance
C) Overriding
D) Polymorphism
A) Overloading
B) Inheritance
C) Overriding
D) Polymorphism
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
7
The children of a virtual base class cannot be used as a base to another class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
8
A ____ function cannot be inherited.
A) virtual
B) friend
C) public
D) protected
A) virtual
B) friend
C) public
D) protected
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
9
____ data and functions can be accessed only within a class.
A) public
B) protected
C) private
D) virtual
A) public
B) protected
C) private
D) virtual
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
10
Any child class function with the same name as the parent, yet with an argument list that differs from the parent's, ____ the parent function.
A) specializes
B) generalizes
C) overloads
D) overrides
A) specializes
B) generalizes
C) overloads
D) overrides
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
11
The three access specifiers available for class members in C++ are: public , private and ____.
A) virtual
B) restricted
C) friend
D) protected
A) virtual
B) restricted
C) friend
D) protected
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
12
Any child class function with the same name and argument list as the parent ____ the parent function.
A) specializes
B) generalizes
C) overloads
D) overrides
A) specializes
B) generalizes
C) overloads
D) overrides
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
13
No matter which access specifier you use when creating a child class, access to parent class members never becomes more lenient than originally coded.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
14
To be truly "object-oriented," a programming language must allow inheritance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
15
The ____ access specifier allows members to be used by class member functions and by derived classes, but not by other parts of a program.
A) protected
B) virtual
C) private
D) friend
A) protected
B) virtual
C) private
D) friend
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
16
C++ programmers usually use the ____ access specifier for inheritance.
A) public
B) protected
C) private
D) friend
A) public
B) protected
C) private
D) friend
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
17
____ data and functions can be accessed anywhere the class is in scope.
A) public
B) protected
C) private
D) virtual
A) public
B) protected
C) private
D) virtual
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
18
A derived class is also called a subclass or descendant.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
19
Class friendship is not inherited.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
20
Inheritance is said to use the ____ relationship.
A) "has a"
B) "extends"
C) "is a"
D) "specializes"
A) "has a"
B) "extends"
C) "is a"
D) "specializes"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
21
Why are functions sometime overridden in derived classes?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
22
Multiple inheritance is ____ required.
A) always
B) never
C) rarely
D) frequently
A) always
B) never
C) rarely
D) frequently
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
23
When a derived class object is destroyed, the ____________________ class destructor is called first.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
24
When a child class function overrides a parent class function, you can say that you have ____________________ the function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
25
The following code is an example of the correct use of the virtual keyword (assume Student is a subclass of Person ): ____.
A) virtual public Person
B) class Student : public Person (virtual)
C) virtual class Student : public Person
D) class Student : virtual public Person
A) virtual public Person
B) class Student : public Person (virtual)
C) virtual class Student : public Person
D) class Student : virtual public Person
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
26
A(n) ____________________ class is also called the superclass, or ancestor.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
27
Many of the constructor complications that occur when inheriting from multiple classes are minimized if you always include ____.
A) a default constructor for every class
B) the virtual keyword when declaring the parent class
C) a friend function
D) an specialized destructor
A) a default constructor for every class
B) the virtual keyword when declaring the parent class
C) a friend function
D) an specialized destructor
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
28
When you instantiate a class object that has been derived from another class, ____.
A) the constructor for the base class is called first, followed by the derived class constructor
B) the constructor for the derived class is called first, followed by the base class constructor
C) only the constructor for the derived class is called
D) only the constructor for the base class is called
A) the constructor for the base class is called first, followed by the derived class constructor
B) the constructor for the derived class is called first, followed by the base class constructor
C) only the constructor for the derived class is called
D) only the constructor for the base class is called
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
29
Overriding a base class member function with a derived member function demonstrates the concept of ____.
A) abstraction
B) polymorphism
C) inheritance
D) overloading
A) abstraction
B) polymorphism
C) inheritance
D) overloading
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
30
____________________ in C++ means you can create classes that derive their attributes from existing classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
31
Provide an example of a situation in which you would want to use inheritance when creating classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
32
If a base class contains a function that the derived class should not have, you can create a ____________________ function with the same name in the derived class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
33
With respect to inheritance, what do generalization and specialization mean?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
34
Consider the following code segments:
class Person
{
private:
int idNum;
string lastName;
string firstName;
public:
void setFields(int, string, string);
void outputData();
};
class Customer : public Person
{
private:
double balanceDue;
public:
void setBalDue(double);
void outputBalDue();
};
void Customer::outputBalDue()
{
cout
What error does the outputBalDue() function have?
class Person
{
private:
int idNum;
string lastName;
string firstName;
public:
void setFields(int, string, string);
void outputData();
};
class Customer : public Person
{
private:
double balanceDue;
public:
void setBalDue(double);
void outputBalDue();
};
void Customer::outputBalDue()
{
cout
What error does the outputBalDue() function have?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
35
What are the advantages provided by inheritance?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
36
Why does inheritance save you time?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
37
Consider an object aWorker of class Worker , and a variable aPerson of class Person , where Worker is a subclass of Person . Which of the following is valid without writing a specialized function?
A) aPerson + aWorker
B) aPerson * aWorker
C) aWorker = aPerson
D) aPerson = aWorker
A) aPerson + aWorker
B) aPerson * aWorker
C) aWorker = aPerson
D) aPerson = aWorker
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
38
If you do not use an access specifier when you create a derived class, access is ____________________ by default.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
39
What should be the first line of the class declaration for the class RV that is both a Vehicle and a Dwelling ?
A) class RV : public Vehicle && public Dwelling
B) class RV : public Vehicle and implements public Dwelling
C) class RV : public Vehicle, public Dwelling
D) class RV : public Vehicle Dwelling
A) class RV : public Vehicle && public Dwelling
B) class RV : public Vehicle and implements public Dwelling
C) class RV : public Vehicle, public Dwelling
D) class RV : public Vehicle Dwelling
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
40
When you define a derived class, you can insert one of the three class access specifiers just prior to the ____________________ name.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
41
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
42
What happens if a derived class uses the protected access specifier for inheritance?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
43
What are the items that are never inherited by a child class?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
44
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
45
Can you create an array of parent class objects and store child class objects in it? What happens when you do this?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
46
Consider the following code fragments:
class PetStoreItem
{
protected:
int stockNum;
double price;
public:
PetStoreItem(int, double);
};
class PetStoreAnimal : public PetStoreItem
{
protected:
int petAge;
public:
PetStoreAnimal(int);
};
PetStoreAnimal::PetStoreAnimal(int age)
{
petAge = age;
}
Change the PetStoreAnimal constructor to avoid getting an error.
class PetStoreItem
{
protected:
int stockNum;
double price;
public:
PetStoreItem(int, double);
};
class PetStoreAnimal : public PetStoreItem
{
protected:
int petAge;
public:
PetStoreAnimal(int);
};
PetStoreAnimal::PetStoreAnimal(int age)
{
petAge = age;
}
Change the PetStoreAnimal constructor to avoid getting an error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
47
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
48
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
49
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
50
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
51
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
52
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck
53
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 53 في هذه المجموعة.
فتح الحزمة
k this deck