Filters
Question type

Study Flashcards

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.

Correct Answer

verifed

verified

Using the protected keyword also gives a member:


A) public access.
B) package access.
C) private access.
D) block scope.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

C

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.

Correct Answer

verifed

verified

C

Superclass methods with this level of access cannot be called from subclasses.


A) private.
B) public.
C) protected.
D) package.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

Which method changes the text the label displays?


A) changeText.
B) setText.
C) changeLabel.
D) setLabel.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

Class ________ represents an image that can be displayed on a JLabel.


A) Image.
B) Icon.
C) ImageIcon.
D) IconImage.

Correct Answer

verifed

verified

Inheritance is also known as the


A) knows-a relationship.
B) has-a relationship.
C) uses-a relationship.
D) is-a relationship.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

The default implementation of method clone of Object performs a ________.


A) empty copy.
B) deep copy.
C) full copy.
D) shallow copy.

Correct Answer

verifed

verified

Every class in Java,except ________,extends an existing class.


A) Integer.
B) Object.
C) String.
D) Class.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

D

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.

Correct Answer

verifed

verified

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.

Correct Answer

verifed

verified

Showing 1 - 20 of 22

Related Exams

Show Answer