JAVA练习题含答案-answer to practice 7
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Chapter 7
Inheritance
Multiple Choice
1)Inheritance is the process by which a new class – known as a _________ - is created from another
class, called the _____________.
base class, derived class
derived class, base class
inherited class, base class
base class, inherited class
Answer:B
2)Inheritance promotes code ___________.
reinvention
reuse
repeats
all of the above
Answer:B
3)The keyword extends indicates:
encapsulation
polymorphism
inheritance
none of the above
Answer:C
4) A derived class is also called a
sub class
super class
base class
all of the above
Answer:A
Copyright © 2006 Pearson Education Addison-Wesley. All rights reserved. 1
2 Walter Savitch •Absolute Java 2/e Chapter 7 Test Bank
5) A super class is also called a
derived class
dominant class
sub class
base class
Answer:D
6)What does a derived class automatically inherit from the base class?
instance variables
static variables
public methods
all of the above
Answer:D
7)If the final modifier is added to the definition of a method, this means:
The method may be redefined in the derived class.
The method may be redefined in the sub class.
The method may not be redefined in the derived class.
None of the above.
Answer:C
8) A base class is synonymous with a:
Child class
Parent class
Derived class
Sub class
Answer:B
9)The special syntax for invoking a constructor of the base class is:
super()
base()
parent()
child()
Answer:A
10)An object of a derived class has the type of the derived class, and it also has the type of the base
class, and more generally, has the type of every one of its ___________ classes.
descendant
child
ancestor
sub
Answer:C
Copyright © 2006 Pearson Education Addison-Wesley. All rights reserved.
Chapter 7 Inheritance 3 11)In using the keyword this in place of super(), the invocation of this must be the ___________
action taken by the constructor.
first
last
it does not matter
none of the above
Answer:A
12) A method or instance variable modified by protected:
can not be accessed by name inside its own class definitions.
can not be accessed by name inside any class derived from it.
can not be accessed by name in the definition of any class in the same package.
can not be accessed by name in any other class (that is, other than classes named in a-c.).
Answer:D
13)If an instance variable is not modified by public, protected or private then it is said to have:
Package access
Default access
Friendly access
All of the above
Answer:D
14)The class __________ is an ancestor class of all Java classes.
String
Object
Math
JFrame
Answer:B
15)The Object class contains the method:
getClass()
toString()
equals()
all of the above
Answer:D
16)The equals method for a class should have _________ as the type of its one parameter.
String
Object
Integer
Double
Answer:B
Copyright © 2004 Addison-Wesley. All rights reserved.