java单选题附答案

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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 (and possibly errors), use ________, rather than ________. a. b. c. d. inheritance, the “copy-and-past” approach. the “copy-and-past” approach, inheritance. a class that explicitly extends Object, a class that does not extend Object. a class that does not extend Object, a class that explicitly extends Object.
private fields of a superclass can be accessed in a subclass a. b. c. d. by calling private methods declared in the superclass. by calling public or protected methods declared in the superclass. directly. All of the above.
Using the protected keyword gives a member: a. b. c. d. public access. package access. private access. block scope.
Βιβλιοθήκη Baidu
Superclass methods with this level of access cannot be called from subclasses. a. b. c. d. private. public. protected. package.
Solutions
ANS: b. A superclass object is a subclass object. ANS: d. “is-a” relationship ANS: c. Objects of a subclass can be treated like objects of their superclass. ANS: d. super. ANS: b. package access. ANS: a. private. ANS: b. Object. ANS: b. Overridden methods have the same signature. ANS: a. inheritance, the “copy-and-past” approach. ANS: d. A reference of type A can be treated as a reference of type B. The converse is true because class A is the superclass. ANS: b. keyword super, followed by a set of parentheses containing the superclass constructor arguments. ANS: b. protected instance variables and methods. ANS: d. All of the above. ANS: b. by calling public or protected methods declared in the superclass. ANS: c. infinite recursion. ANS: d. The program compiles and runs because the instance variables are initialized to their default values. ANS: a. All of the above. ANS: c. All animals lay eggs except for mammals. ANS: a. whether two references refer to the same object in memory
Every class in Java, except ________, extends an existing class. a. b. c. d. Integer. Object. String. Class.
Overriding a method differs from overloading a method because: a. b. c. d. Overloaded methods have the same signature. Overridden methods have the same signature. Both of the above. Neither of the above.
Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass’s method causes a(n) ________. a. b. c. d. compile-time error. syntax error. infinite recursion. runtime error.
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. d. keyword super, followed by a dot and the superclass constructor name. None of the above.
The default equals implementation determines: a. b. c. d. whether two references refer to the same object in memory. whether two references have the same type. whether two objects have the same instance variables. whether two objects have the same instance variable values.
Practice Test 1
Which of the following statements is false? a. b. A subclass is generally larger than its superclass. A superclass object is a subclass object.
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. b. c. A syntax error occurs. A compile-time error occurs. A run-time error occurs.
Which superclass members are inherited by all subclasses of that superclass? a. b. c. d. private instance variables and methods. protected instance variables and methods. private constructors. protected constructors.
Which of the following is an example of a functionality that should not be “factored out” to a superclass? a. b. c. d. Both ducks and geese are birds that know how to start flying from the water. All vehicles know how to start and stop. All animals lay eggs, except for mammals. All paints have a color.
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. b. c. d. Both variables a and b are instance variables. After the constructor for class B executes, the variable a will have the value 7. After the constructor for class B executes, the variable b will have the value 8. A reference of type A can be treated as a reference of type B.
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.
Inheritance is also known as the a. b. c. d. “knows-a” relationship. “has-a” relationship. “uses-a” relationship. “is-a” relationship.
An advantage of inheritance is that: a. b. c. d. All methods can be inherited. All instance variables can be uniformly accessed by subclasses and superclasses. Objects of a subclass can be treated like objects of their superclass. None of the above.
d. The program compiles and runs because the instance variables are initialized to their default values.
Which of the following statements are true? A. B. C. D. a. b. c. d. We can use inheritance to customize existing software. A superclass specifies commonality. A superclass can be modified without modifying subclasses A subclass can be modified without modifying its superclass. All of the above. None of the above. A, B and C. A, B and D.
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method? a. b. c. d. base. this. public. super.
相关文档
最新文档