Deck 8: Inheritance

ملء الشاشة (f)
exit full mode
سؤال
A class declared as final _________________________________ .

A) cannot be changed.
B) cannot have subclasses.
C) cannot have superclasses.
D) has several abstract methods.
E) cannot be used in a program.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Methods and variables declared as private in a parent class cannot be accessed in a child class.
سؤال
The special reference _________________ is used to refer to the parent class in a child class.

A) this
B) super
C) null
D) parent
E) none of the above
سؤال
Once a method is overridden in a subclass, the original version can never be referenced from within the subclass.
سؤال
In Java subclass can only extend one parent class.
سؤال
The original class that is used to derive a new class using inheritance is called ____________________ .

A) a superclass
B) a parent class
C) a base class
D) all of the above
E) neither a, b, nor c
سؤال
If a subclasses constructor does not make an explicit call to a superclass's constructor, ______________________ .

A) a run-time error will result.
B) a compile-time error will result.
C) the constructor will be called anyway.
D) the class will be implicitly declared as abstract.
E) none of the above
سؤال
The derived class created using inheritace is called ______________________ .

A) a child class
B) a superclass
C) a parent class
D) all of the above
E) neither a, b, nor c
سؤال
A _______________________ class represents a generic concept in a class hierarchy.

A) super
B) abstract
C) interface
D) shadow
E) generic
سؤال
A child class is allowed to define a method with the same name and parameter list as a method in the parent class.
سؤال
Which of the following key words indicates a new class is being derived from an existing class?

A) super
B) final
C) extends
D) inherits
E) expands
سؤال
To invoke a parents constructor in a subclass, we use the ______________ method.

A) abstract
B) construct
C) parent
D) super
E) extends
سؤال
The process of inheritance should establish a(n) ___________________ relationship.

A) is-a
B) has-a
C) static
D) not-a
E) none of the above
سؤال
In order for derived classed to have access to encapsulated data members and methods of superclasses, the data members and methods should be declared using the ____________________ modifier.

A) private
B) public
C) protected
D) final
E) static
سؤال
When designing a class hierarchy, it is important that common features be ________________________ .

A) higher in the class hierarchy.
B) lower in the class hierarchy.
C) near the middle of the class hierarchy.
D) in abstract classes.
E) in the Object class.
سؤال
Which of the following methods are included in every class created in Java by inheritance?

A) next
B) toString
C) compareTo
D) charAt
E) none of the above
سؤال
Of the classes below, the one that is most likely to be declared abstract is _________________.

A) Bat
B) Squirrel
C) Animal
D) Iguana
E) Parrot
سؤال
All Java classes are subclasses of the ___________________ class.

A) String
B) java.lang
C) Java
D) Class
E) Object
سؤال
When a variable is declared in a subclass has the same name as a variable declared in a superclass, it is called a _______________ variable.

A) final
B) shadow
C) static
D) dead
E) this is not allowed in Java
سؤال
Java supports multiple inheritance.
سؤال
What is a shadow variable?
سؤال
What does it mean for a class to be declared as final? What does it mean for a method to be declared as final?
سؤال
Explain what it means for a child class to override a parent class. Why might this be useful?
سؤال
What is an abstract class, and why might it be useful in an inheritance hierarchy?
سؤال
Inheritance should not be considered in the software design process.
سؤال
Explain how a subclass can can access its parent classes private instance variables and methods.
سؤال
An abstract class must contain abstract methods.
سؤال
Explain the relevance of the Object class to the Java programming language.
سؤال
It is possible to derive a class from an abstract class without overriding all of the parents abstract methods.
سؤال
It makes sense to declare most abstract methods as final.
سؤال
Can a class be a parent of more than one subclass? Can a class be a child of more than one parent? Explain.
سؤال
A child class is allowed to declare a variable with the same name as one that is contained in the parent class.
سؤال
Explain why inheritance is useful.
سؤال
Describe the behavior of the toString method and the equals method of the Object class.
سؤال
Draw a hierarchy of Animals. The hierarchy should include the following entities: Animal, Reptile, Mammal, Bear, Human, Iguana, and Dolphin.
سؤال
A programmer tries to create a subclass of String called MyString. When the programmer compiles her new class, the compiler produces the following message:
MyString.java:1: cannot inherit from final java.lang.String
public class MyString extends String {
^
1 error
Explain the cause of this error.
سؤال
Consider an software system that will implement the following classes: Student, Professor, StaffMember, ContractWorker. List some common attributes of these classes. What would be a good abstract class from which these classes may be extended via inheritance?
سؤال
Suppose we create a subclass from a class that has a method called someMethod. If we override someMethod in the subclass, is it possible to access the superclass's version of someMethod? If so, how?
سؤال
Draw a hierarchy of people at a University.
سؤال
Compare and contrast the private visibility modifier to the protected visibility modifier. Why is the protected visibility modifier a better choice in an inheritance hierarchy?
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 8: Inheritance
1
A class declared as final _________________________________ .

A) cannot be changed.
B) cannot have subclasses.
C) cannot have superclasses.
D) has several abstract methods.
E) cannot be used in a program.
B
Explanation: The final modifier restricts inheritance. In particular, a class declared as final cannot have subclasses.
2
Methods and variables declared as private in a parent class cannot be accessed in a child class.
True
Explanation: In order for a child class to have access to the private data and methods of a parent class, they should be declared using the protected modifier, which still enforces encapsulation, but allows for flexibility in an inheritance hierarchy.
3
The special reference _________________ is used to refer to the parent class in a child class.

A) this
B) super
C) null
D) parent
E) none of the above
B
Explanation: The super reference refers to the parent class in a derived class.
4
Once a method is overridden in a subclass, the original version can never be referenced from within the subclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
In Java subclass can only extend one parent class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
The original class that is used to derive a new class using inheritance is called ____________________ .

A) a superclass
B) a parent class
C) a base class
D) all of the above
E) neither a, b, nor c
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
If a subclasses constructor does not make an explicit call to a superclass's constructor, ______________________ .

A) a run-time error will result.
B) a compile-time error will result.
C) the constructor will be called anyway.
D) the class will be implicitly declared as abstract.
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
The derived class created using inheritace is called ______________________ .

A) a child class
B) a superclass
C) a parent class
D) all of the above
E) neither a, b, nor c
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
A _______________________ class represents a generic concept in a class hierarchy.

A) super
B) abstract
C) interface
D) shadow
E) generic
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
A child class is allowed to define a method with the same name and parameter list as a method in the parent class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following key words indicates a new class is being derived from an existing class?

A) super
B) final
C) extends
D) inherits
E) expands
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
To invoke a parents constructor in a subclass, we use the ______________ method.

A) abstract
B) construct
C) parent
D) super
E) extends
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
The process of inheritance should establish a(n) ___________________ relationship.

A) is-a
B) has-a
C) static
D) not-a
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
In order for derived classed to have access to encapsulated data members and methods of superclasses, the data members and methods should be declared using the ____________________ modifier.

A) private
B) public
C) protected
D) final
E) static
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
When designing a class hierarchy, it is important that common features be ________________________ .

A) higher in the class hierarchy.
B) lower in the class hierarchy.
C) near the middle of the class hierarchy.
D) in abstract classes.
E) in the Object class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
Which of the following methods are included in every class created in Java by inheritance?

A) next
B) toString
C) compareTo
D) charAt
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
Of the classes below, the one that is most likely to be declared abstract is _________________.

A) Bat
B) Squirrel
C) Animal
D) Iguana
E) Parrot
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
All Java classes are subclasses of the ___________________ class.

A) String
B) java.lang
C) Java
D) Class
E) Object
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
When a variable is declared in a subclass has the same name as a variable declared in a superclass, it is called a _______________ variable.

A) final
B) shadow
C) static
D) dead
E) this is not allowed in Java
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
Java supports multiple inheritance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
What is a shadow variable?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
What does it mean for a class to be declared as final? What does it mean for a method to be declared as final?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
Explain what it means for a child class to override a parent class. Why might this be useful?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
What is an abstract class, and why might it be useful in an inheritance hierarchy?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
Inheritance should not be considered in the software design process.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
Explain how a subclass can can access its parent classes private instance variables and methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
An abstract class must contain abstract methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
Explain the relevance of the Object class to the Java programming language.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
It is possible to derive a class from an abstract class without overriding all of the parents abstract methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
It makes sense to declare most abstract methods as final.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
Can a class be a parent of more than one subclass? Can a class be a child of more than one parent? Explain.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
A child class is allowed to declare a variable with the same name as one that is contained in the parent class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
Explain why inheritance is useful.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
Describe the behavior of the toString method and the equals method of the Object class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
Draw a hierarchy of Animals. The hierarchy should include the following entities: Animal, Reptile, Mammal, Bear, Human, Iguana, and Dolphin.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
A programmer tries to create a subclass of String called MyString. When the programmer compiles her new class, the compiler produces the following message:
MyString.java:1: cannot inherit from final java.lang.String
public class MyString extends String {
^
1 error
Explain the cause of this error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
Consider an software system that will implement the following classes: Student, Professor, StaffMember, ContractWorker. List some common attributes of these classes. What would be a good abstract class from which these classes may be extended via inheritance?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
Suppose we create a subclass from a class that has a method called someMethod. If we override someMethod in the subclass, is it possible to access the superclass's version of someMethod? If so, how?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
Draw a hierarchy of people at a University.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
Compare and contrast the private visibility modifier to the protected visibility modifier. Why is the protected visibility modifier a better choice in an inheritance hierarchy?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.