Deck 9: Object Oriented Programming: Inheritance
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/23
العب
ملء الشاشة (f)
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.
{
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.
D
2
Which of the following statements is (are)true? A.We can use inheritance to customize existing software.
B)A superclass specifies commonality.
C)A superclass can be modified without modifying subclasses
D)A subclass can be modified without modifying its superclass.
A)All of the above.
B)None of the above.
C)A,B and C.
D)A,B and D.
B)A superclass specifies commonality.
C)A superclass can be modified without modifying subclasses
D)A subclass can be modified without modifying its superclass.
A)All of the above.
B)None of the above.
C)A,B and C.
D)A,B and D.
A
3
Superclass methods with this level of access cannot be called from subclasses.
A)private.
B)public.
C)protected.
D)package.
A)private.
B)public.
C)protected.
D)package.
A
4
The default implementation of method clone of Object performs a ________.
A)empty copy.
B)deep copy.
C)full copy.
D)shallow copy.
A)empty copy.
B)deep copy.
C)full copy.
D)shallow copy.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
5
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.
A)Overloaded methods have the same signature.
B)Overridden methods have the same signature.
C)Both of the above.
D)Neither of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
6
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.
A)private instance variables and methods.
B)protected instance variables and methods.
C)private constructors.
D)protected constructors.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which of the following is not a superclass/subclass relationship?
A)Ford/Taurus.
B)University/Boston University.
C)Sailboat/Tugboat.
D)Country/USA.
A)Ford/Taurus.
B)University/Boston University.
C)Sailboat/Tugboat.
D)Country/USA.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
8
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
9
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
10
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
11
To avoid duplicating code,use ________,rather than ________.
A)inheritance,the "copy-and-past" approach.
B)the "copy-and-past" 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.
A)inheritance,the "copy-and-past" approach.
B)the "copy-and-past" 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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
12
Which of the following is an example of a functionality that should not be "factored out" to a superclass?
A)Both ducks and geese are birds that know how to start flying from the water.
B)All vehicles know how to start and stop.
C)All animals lay eggs,except for mammals.
D)All paints have a color.
A)Both ducks and geese are birds that know how to start flying from the water.
B)All vehicles know how to start and stop.
C)All animals lay eggs,except for mammals.
D)All paints have a color.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
13
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.
A)base.
B)this.
C)public.
D)super.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
14
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
15
Inheritance is also known as the
A)"knows-a" relationship.
B)"has-a" relationship.
C)"uses-a" relationship.
D)"is-a" relationship.
A)"knows-a" relationship.
B)"has-a" relationship.
C)"uses-a" relationship.
D)"is-a" relationship.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
16
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
17
Every class in Java,except ________,extends an existing class.
A)Integer.
B)Object.
C)String.
D)Class.
A)Integer.
B)Object.
C)String.
D)Class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
18
Using the protected keyword gives a member:
A)public access.
B)package access.
C)private access.
D)block scope.
A)public access.
B)package access.
C)private access.
D)block scope.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
19
Failure to prefix the superclass method name with the keyword super and a dot (. )separator when referencing the superclass's method causes ________.
A)a compile-time error.
B)a syntax error.
C)infinite recursion.
D)a runtime error.
A)a compile-time error.
B)a syntax error.
C)infinite recursion.
D)a runtime error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
20
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which method changes the text the label displays?
A)changeText.
B)setText.
C)changeLabel.
D)setLabel.
A)changeText.
B)setText.
C)changeLabel.
D)setLabel.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
22
Class ________ represents an image that can be displayed on a JLabel.
A)Image.
B)Icon.
C)ImageIcon.
D)IconImage.
A)Image.
B)Icon.
C)ImageIcon.
D)IconImage.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck
23
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 23 في هذه المجموعة.
فتح الحزمة
k this deck