Deck 9: Object-Oriented Programming: Inheritance

ملء الشاشة (f)
exit full mode
سؤال
Consider the classes below, declared in the same file:
class A {
Int a;
Public A() {
A = 7;
}
}
Class B extends A {
Int b;
Public B() {
B = 8;
}
}
Which of the statements below is false?

A) Both variables a and b are instance variables.
B) After the constructor for class B executes, the variable a will have the value 7.
C) After the constructor for class B executes, the variable b will have the value 8.
D) A reference of type A can be treated as a reference of type B.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

A) base.
B) this.
C) public.
D) super.
سؤال
When overriding a superclass method and calling the superclass version from the subclass method, failure to prefix the superclass method name with the keyword super and a dot (.) in the superclass method call causes ________.

A) a compile-time error.
B) a syntax error.
C) infinite recursion.
D) a runtime error.
سؤال
Superclass methods with this level of access cannot be called from subclasses.

A) private.
B) public.
C) protected.
D) package.
سؤال
An advantage of inheritance is that:

A) All methods can be inherited.
B) All instance variables can be uniformly accessed by subclasses and superclasses.
C) Objects of a subclass can be treated like objects of their superclass.
D) None of the above.
سؤال
Using the protected keyword also gives a member:

A) public access.
B) package access.
C) private access.
D) block scope.
سؤال
Which superclass members are inherited by all subclasses of that superclass?

A) private instance variables and methods.
B) protected instance variables and methods.
C) private constructors.
D) protected constructors.
سؤال
Every class in Java, except ________, extends an existing class.

A) Integer.
B) Object.
C) String.
D) Class.
سؤال
Inheritance is also known as the

A) knows-a relationship.
B) has-a relationship.
C) uses-a relationship.
D) is-a relationship.
سؤال
Which of the following is the superclass constructor call syntax?

A) keyword super, followed by a dot (.) .
B) keyword super, followed by a set of parentheses containing the superclass constructor arguments.
C) keyword super, followed by a dot and the superclass constructor name.
D) None of the above.
سؤال
When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable?

A) A syntax error occurs.
B) A compile-time error occurs.
C) A run-time error occurs.
D) The program compiles and runs because the instance variables are initialized to their default values.
سؤال
Private fields of a superclass can be accessed in a subclass

A) by calling private methods declared in the superclass.
B) by calling public or protected methods declared in the superclass.
C) directly.
D) All of the above.
سؤال
Overriding a method differs from overloading a method because:

A) Overloaded methods have the same signature.
B) Overridden methods have the same signature.
C) Both of the above.
D) Neither of the above.
سؤال
Which of the following is not a superclass/subclass relationship?

A) Employee/Hourly Employee.
B) Vehicle/Car.
C) Sailboat/Tugboat.
D) None of the above.
سؤال
The default equals implementation of class Object determines:

A) whether two references refer to the same object in memory.
B) whether two references have the same type.
C) whether two objects have the same instance variables.
D) whether two objects have the same instance variable values.
سؤال
Which of the following statements is false?

A) A subclass is often larger than its superclass.
B) A superclass object is a subclass object.
C) The class following the extends keyword in a class declaration is the direct superclass of the class being declared.
D) Java uses interfaces to provide the benefits of multiple inheritance.
سؤال
To avoid duplicating code, use ________, rather than ________.

A) inheritance, the "copy-and-past" approach.
B) the "copy-and-paste" approach, inheritance.
C) a class that explicitly extends Object, a class that does not extend Object.
D) a class that does not extend Object, a class that explicitly extends Object.
سؤال
The default implementation of method clone of Object performs a ________.

A) empty copy.
B) deep copy.
C) full copy.
D) shallow copy.
سؤال
Which statement is true when a superclass has protected instance variables?

A) A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state.
B) Subclass methods are more likely to be written so that they depend on the superclass's data implementation.
C) We may need to modify all the subclasses of the superclass if the superclass implementation changes.
D) All of the above.
سؤال
Which of the following statements is false?

A) A class can directly inherit from class Object.
B) It's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
C) If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly.
D) A class's instance variables are normally declared private to enforce good software engineering.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/20
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 9: Object-Oriented Programming: Inheritance
1
Consider the classes below, declared in the same file:
class A {
Int a;
Public A() {
A = 7;
}
}
Class B extends A {
Int b;
Public B() {
B = 8;
}
}
Which of the statements below is false?

A) Both variables a and b are instance variables.
B) After the constructor for class B executes, the variable a will have the value 7.
C) After the constructor for class B executes, the variable b will have the value 8.
D) A reference of type A can be treated as a reference of type B.
A reference of type A can be treated as a reference of type B.
2
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

A) base.
B) this.
C) public.
D) super.
D
3
When overriding a superclass method and calling the superclass version from the subclass method, failure to prefix the superclass method name with the keyword super and a dot (.) in the superclass method call causes ________.

A) a compile-time error.
B) a syntax error.
C) infinite recursion.
D) a runtime error.
infinite recursion.
4
Superclass methods with this level of access cannot be called from subclasses.

A) private.
B) public.
C) protected.
D) package.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
5
An advantage of inheritance is that:

A) All methods can be inherited.
B) All instance variables can be uniformly accessed by subclasses and superclasses.
C) Objects of a subclass can be treated like objects of their superclass.
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
6
Using the protected keyword also gives a member:

A) public access.
B) package access.
C) private access.
D) block scope.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which superclass members are inherited by all subclasses of that superclass?

A) private instance variables and methods.
B) protected instance variables and methods.
C) private constructors.
D) protected constructors.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
8
Every class in Java, except ________, extends an existing class.

A) Integer.
B) Object.
C) String.
D) Class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
9
Inheritance is also known as the

A) knows-a relationship.
B) has-a relationship.
C) uses-a relationship.
D) is-a relationship.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following is the superclass constructor call syntax?

A) keyword super, followed by a dot (.) .
B) keyword super, followed by a set of parentheses containing the superclass constructor arguments.
C) keyword super, followed by a dot and the superclass constructor name.
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
11
When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable?

A) A syntax error occurs.
B) A compile-time error occurs.
C) A run-time error occurs.
D) The program compiles and runs because the instance variables are initialized to their default values.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
12
Private fields of a superclass can be accessed in a subclass

A) by calling private methods declared in the superclass.
B) by calling public or protected methods declared in the superclass.
C) directly.
D) All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
13
Overriding a method differs from overloading a method because:

A) Overloaded methods have the same signature.
B) Overridden methods have the same signature.
C) Both of the above.
D) Neither of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
14
Which of the following is not a superclass/subclass relationship?

A) Employee/Hourly Employee.
B) Vehicle/Car.
C) Sailboat/Tugboat.
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
15
The default equals implementation of class Object determines:

A) whether two references refer to the same object in memory.
B) whether two references have the same type.
C) whether two objects have the same instance variables.
D) whether two objects have the same instance variable values.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
16
Which of the following statements is false?

A) A subclass is often larger than its superclass.
B) A superclass object is a subclass object.
C) The class following the extends keyword in a class declaration is the direct superclass of the class being declared.
D) Java uses interfaces to provide the benefits of multiple inheritance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
17
To avoid duplicating code, use ________, rather than ________.

A) inheritance, the "copy-and-past" approach.
B) the "copy-and-paste" approach, inheritance.
C) a class that explicitly extends Object, a class that does not extend Object.
D) a class that does not extend Object, a class that explicitly extends Object.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
18
The default implementation of method clone of Object performs a ________.

A) empty copy.
B) deep copy.
C) full copy.
D) shallow copy.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
19
Which statement is true when a superclass has protected instance variables?

A) A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state.
B) Subclass methods are more likely to be written so that they depend on the superclass's data implementation.
C) We may need to modify all the subclasses of the superclass if the superclass implementation changes.
D) All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
20
Which of the following statements is false?

A) A class can directly inherit from class Object.
B) It's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
C) If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly.
D) A class's instance variables are normally declared private to enforce good software engineering.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 20 في هذه المجموعة.