Deck 9: Inheritance
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/99
Play
Full screen (f)
Deck 9: Inheritance
1
You are creating a class inheritance hierarchy about motor vehicles that will contain classes named Vehicle, Auto, and Motorcycle.Which of the following statements is correct?
A.Vehicle should be the default class, while Auto and Motorcycle should be the subclasses.
B.Vehicle should be the superclass, while Auto and Motorcycle should be the subclasses.
C.Vehicle should be the subclass, while Auto and Motorcycle should be the superclasses.
D.Vehicle should be the subclass, while Auto and Motorcycle should be the default classes.
A.Vehicle should be the default class, while Auto and Motorcycle should be the subclasses.
B.Vehicle should be the superclass, while Auto and Motorcycle should be the subclasses.
C.Vehicle should be the subclass, while Auto and Motorcycle should be the superclasses.
D.Vehicle should be the subclass, while Auto and Motorcycle should be the default classes.
B
2
Consider the classes shown below:
A.Line 1 only
B.Line 2 only
C.Lines 1 and 2
D.Neither line will compile without error

A.Line 1 only
B.Line 2 only
C.Lines 1 and 2
D.Neither line will compile without error
C
3
Consider the following inheritance hierarchy diagram:
Which of the following statements is correct?
A.Auto class inherits from LandVehicle class, and LandVehicle class inherits from Vehicle class.
B.Auto class inherits from LandVehicle class, and Vehicle class inherits from LandVehicle class.
C.LandVehicle class inherits from Auto class, and LandVehicle class inherits from Vehicle class.
D.LandVehicle class inherits from Auto class, and Vehicle class inherits from LandVehicle class.

A.Auto class inherits from LandVehicle class, and LandVehicle class inherits from Vehicle class.
B.Auto class inherits from LandVehicle class, and Vehicle class inherits from LandVehicle class.
C.LandVehicle class inherits from Auto class, and LandVehicle class inherits from Vehicle class.
D.LandVehicle class inherits from Auto class, and Vehicle class inherits from LandVehicle class.
A
4
All hamsters are rodents and all rodents are mammals.What hierarchy best captures this information?
A.Hamster is a superclass of Rodent and Rodent is a superclass of Mammal
B.Mammal is a superclass of Rodent and Rodent is a superclass of Hamster
C.Mammal is a superclass of Rodent and Hamster
D.Hamster is a superclass of Rodent and Mammal
A.Hamster is a superclass of Rodent and Rodent is a superclass of Mammal
B.Mammal is a superclass of Rodent and Rodent is a superclass of Hamster
C.Mammal is a superclass of Rodent and Hamster
D.Hamster is a superclass of Rodent and Mammal
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
5
Which class represents a more specific entity in an inheritance hierarchy?
A.Default class
B.Superclass
C.Subclass.
D.Inheritance class.
A.Default class
B.Superclass
C.Subclass.
D.Inheritance class.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following statements about inheritance is correct?
A.You can always use a superclass object in place of a subclass object.
B.You can always use a subclass object in place of a superclass object.
C.A superclass inherits data and behavior from a subclass.
D.A superclass inherits only behavior from a subclass.
A.You can always use a superclass object in place of a subclass object.
B.You can always use a subclass object in place of a superclass object.
C.A superclass inherits data and behavior from a subclass.
D.A superclass inherits only behavior from a subclass.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
7
Consider the following code snippet:
Which of the following statements is correct?
A.The subclass is shadowing a superclass method.
B.The subclass is overloading a superclass method.
C.The subclass is overriding a superclass method.
D.The subclass is defining its own distinct method.

A.The subclass is shadowing a superclass method.
B.The subclass is overloading a superclass method.
C.The subclass is overriding a superclass method.
D.The subclass is defining its own distinct method.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
8
Consider the following inheritance hierarchy diagram:
Which of the following statements is correct?
A.Auto is a superclass of LandVehicle, and LandVehicle is a superclass of Vehicle.
B.Auto is a superclass of LandVehicle, and LandVehicle is a subclass of Vehicle.
C.Auto is a subclass of LandVehicle, and LandVehicle is a superclass of Vehicle.
D.Auto is a subclass of LandVehicle, and LandVehicle is a subclass of Vehicle.

A.Auto is a superclass of LandVehicle, and LandVehicle is a superclass of Vehicle.
B.Auto is a superclass of LandVehicle, and LandVehicle is a subclass of Vehicle.
C.Auto is a subclass of LandVehicle, and LandVehicle is a superclass of Vehicle.
D.Auto is a subclass of LandVehicle, and LandVehicle is a subclass of Vehicle.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
9
Consider the hierarchy of classes shown below.
What is the direct superclass of the class ScriptedShow?
A.Comedy
B.RealityShow
C.Object
D.TelevisionShow

A.Comedy
B.RealityShow
C.Object
D.TelevisionShow
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
10
Insert the missing code in the following code fragment.This fragment is intended to call the Vessel class's method.
A.SpeedBoat.vesselLength(26.0);
B.Vessel.vesselLength(26.0);
C.vesselLength = 26.0;
D.setVesselClass(26.0);

A.SpeedBoat.vesselLength(26.0);
B.Vessel.vesselLength(26.0);
C.vesselLength = 26.0;
D.setVesselClass(26.0);
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
11
Consider the classes shown below:
A.-7 24
B.24 24
C.-7 -7
D.24 -7

A.-7 24
B.24 24
C.-7 -7
D.24 -7
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
12
Consider the hierarchy of classes shown below.
Which represent valid class headers that would be found in this hierarchy?
A)
B)
C)
D)

A)

B)

C)

D)

Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
13
What is a class called that represents the most general entity in an inheritance hierarchy?
A.Default class.
B.Superclass.
C.Subclass.
D.Inheritance class.
A.Default class.
B.Superclass.
C.Subclass.
D.Inheritance class.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
14
All rodents are mammals and all canines are mammals.No canines are rodents and no rodents are canines.What hierarchy best captures this information?
A.Mammal is a superclass of Rodent and Mammal
B.Rodent is a superclass of Mammal and Canine is a superclass of Mammal
C.Mammal is a superclass of Rodent and Rodent is a superclass of Canine
D.Mammal is a superclass of Canine and Canine is a superclass of Rodent
A.Mammal is a superclass of Rodent and Mammal
B.Rodent is a superclass of Mammal and Canine is a superclass of Mammal
C.Mammal is a superclass of Rodent and Rodent is a superclass of Canine
D.Mammal is a superclass of Canine and Canine is a superclass of Rodent
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
15
Consider the classes shown below:
A.100 100
B.-14 21
C.21 21
D.-14 100

A.100 100
B.-14 21
C.21 21
D.-14 100
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
16
Consider the classes shown below:
A.-14 21
B.21 21
C.21 100
D.100 100

A.-14 21
B.21 21
C.21 100
D.100 100
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
17
Consider the classes shown below:
A.100 100
B.-14 100
C.-14 -14
D.100 -14

A.100 100
B.-14 100
C.-14 -14
D.100 -14
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
18
Consider the classes shown below:
A.Line 1 only
B.Line 2 only
C.Lines 1 and 2
D.Neither line will compile without error

A.Line 1 only
B.Line 2 only
C.Lines 1 and 2
D.Neither line will compile without error
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
19
Consider the hierarchy of classes shown below.
What is the superclass of the class TelevisionShow?
A.Object
B.Comedy
C.RealityShow
D.This class has no superclass

A.Object
B.Comedy
C.RealityShow
D.This class has no superclass
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
20
Insert the missing code in the following code fragment.This fragment is intended to call the Vehicle class's method.
A.Motorcyle.setVehicleClass(2.0);
B.Vehicle.setVehicleClass(2.0);
C.numberAxles = 2.0;
D.setVehicleClass(2.0);

A.Motorcyle.setVehicleClass(2.0);
B.Vehicle.setVehicleClass(2.0);
C.numberAxles = 2.0;
D.setVehicleClass(2.0);
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
21
You are creating a Motorcycle class which is supposed to be a subclass of the Vehicle class.Which of the following class declaration statements will accomplish this?
A.public class Motorcycle extends Vehicle
B.public class Motorcycle implements Vehicle
C.public class Motorcycle interfaces Vehicle
D.public class Motorcycle inherits Vehicle
A.public class Motorcycle extends Vehicle
B.public class Motorcycle implements Vehicle
C.public class Motorcycle interfaces Vehicle
D.public class Motorcycle inherits Vehicle
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
22
What must a subclass do to modify a private superclass instance variable?
A.The subclass must simply use the name of the superclass instance variable.
B.The subclass must declare its own instance variable with the same name as the superclass instance variable.
C.The subclass must use a public method of the superclass (if it exists) to update the superclass's private instance variable.
D.The subclass must have its own public method to update the superclass's private instance variable.
A.The subclass must simply use the name of the superclass instance variable.
B.The subclass must declare its own instance variable with the same name as the superclass instance variable.
C.The subclass must use a public method of the superclass (if it exists) to update the superclass's private instance variable.
D.The subclass must have its own public method to update the superclass's private instance variable.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
23
Consider the following code snippet:
Which of the following statements is true?
A)This method will call itself.
B)This method calls a public method in its subclass.
C)This method calls a private method in its superclass
D)This method calls a public method in its superclass.

A)This method will call itself.
B)This method calls a public method in its subclass.
C)This method calls a private method in its superclass
D)This method calls a public method in its superclass.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
24
Consider the following class hierarchy:
Complete the code in the Auto class method named displayAutoType to return the type data.
A.super(type);
B.super.type;
C.super.super.type;
D.super.displayInfo()

A.super(type);
B.super.type;
C.super.super.type;
D.super.displayInfo()
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
25
Consider the following class hierarchy:
When an object of type Vehicle is constructed, what will be printed by the constructors from this inheritance hierarchy?
A.Vehicle Land Auto
B.Auto Land Vehicle
C.Vehicle
D.Auto

A.Vehicle Land Auto
B.Auto Land Vehicle
C.Vehicle
D.Auto
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is true regarding subclasses?
A)A subclass inherits methods from its superclass but not instance variables.
B)A subclass inherits instance variables from its superclass but not methods.
C)A subclass inherits methods and instance variables from its superclass.
D)A subclass does not inherit methods or instance variables from its superclass.
A)A subclass inherits methods from its superclass but not instance variables.
B)A subclass inherits instance variables from its superclass but not methods.
C)A subclass inherits methods and instance variables from its superclass.
D)A subclass does not inherit methods or instance variables from its superclass.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
27
Which reserved word must be used to call a method of a superclass?
A.this
B.my
C.parent
D.super
A.this
B.my
C.parent
D.super
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
28
Suppose the class Value is partially defined below
A subclass of Value, LargerValue, is defined with a getValue method that returns twice the value of the parent.Which line is the body of LargerValue's getValue method?
A.return getValue() * 2;
B.return super.getValue() * 2;
C.return number * 2;
D.return super.number * 2;

A.return getValue() * 2;
B.return super.getValue() * 2;
C.return number * 2;
D.return super.number * 2;
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following is true regarding subclasses?
A)A subclass has access to private instance variables of its superclass.
B)A subclass does not have access to public instance variables of its superclass.
C)A subclass must specify the implicit parameter to use methods inherited from its superclass.
D)A subclass has no access to private instance variables of its superclass.
A)A subclass has access to private instance variables of its superclass.
B)A subclass does not have access to public instance variables of its superclass.
C)A subclass must specify the implicit parameter to use methods inherited from its superclass.
D)A subclass has no access to private instance variables of its superclass.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements about superclasses and subclasses is true?
A)A superclass is larger than its subclass.
B)A superclass inherits from a subclass.
C)A superclass extends a subclass.
D)A subclass extends a superclass.
A)A superclass is larger than its subclass.
B)A superclass inherits from a subclass.
C)A superclass extends a subclass.
D)A subclass extends a superclass.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following indicates that a class named ClassA class is a superclass of the ClassB class?
A.public class ClassB extends ClassA
B.public class ClassB implements ClassA
C.public class ClassA extends ClassB
D.public class ClassA implements ClassB
A.public class ClassB extends ClassA
B.public class ClassB implements ClassA
C.public class ClassA extends ClassB
D.public class ClassA implements ClassB
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
32
Consider the classes shown below:
A.24 24
B.-7 -7
C.-7 24
D.24 -7

A.24 24
B.-7 -7
C.-7 24
D.24 -7
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
33
Consider the following class hierarchy:
Complete the code in the Auto class constructor to store the type data.
A.super(type);
B.super(super(type));
C.super.super(type);
D.This cannot be done unless Auto declares an instance variable named type.

A.super(type);
B.super(super(type));
C.super.super(type);
D.This cannot be done unless Auto declares an instance variable named type.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
34
Which keyword is used to create a subclass?
A.inherits
B.implements
C.interface
D.extends
A.inherits
B.implements
C.interface
D.extends
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following is true regarding subclasses?
A)A subclass that inherits methods from its superclass may not override the methods.
B)A subclass that inherits instance variables from its superclass may not declare additional instance variables.
C)A subclass may inherit methods or instance variables from its superclass but not both.
D)A subclass may inherit methods and instance variables from its superclass, and may also implement its own methods and declare its own instance variables.
A)A subclass that inherits methods from its superclass may not override the methods.
B)A subclass that inherits instance variables from its superclass may not declare additional instance variables.
C)A subclass may inherit methods or instance variables from its superclass but not both.
D)A subclass may inherit methods and instance variables from its superclass, and may also implement its own methods and declare its own instance variables.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
36
Consider the following code snippet:
If a Motorcycle class is created as a subclass of the Vehicle class, which of the following statements is correct?
A.A Motorcycle object inherits and can directly use both the instance variable manufacturer and the method setVehicleClass.
B.A Motorcycle object inherits and can directly use the instance variable manufacturer but not the method setVehicleClass.
C.A Motorcycle object inherits but cannot directly use either the instance variable manufacturer or the method setVehicleClass.
D.A Motorcycle object inherits and can directly use the method setVehicleClass but cannot directly use the instance variable manufacturer.

A.A Motorcycle object inherits and can directly use both the instance variable manufacturer and the method setVehicleClass.
B.A Motorcycle object inherits and can directly use the instance variable manufacturer but not the method setVehicleClass.
C.A Motorcycle object inherits but cannot directly use either the instance variable manufacturer or the method setVehicleClass.
D.A Motorcycle object inherits and can directly use the method setVehicleClass but cannot directly use the instance variable manufacturer.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
37
Consider the following code snippet:
Which of the following statements is correct?
A.The subclass is shadowing a superclass method.
B.The subclass is overloading a superclass method.
C.The subclass is overriding a superclass method.
D.This code will not compile.

A.The subclass is shadowing a superclass method.
B.The subclass is overloading a superclass method.
C.The subclass is overriding a superclass method.
D.This code will not compile.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
38
Consider the following class hierarchy:
Complete the code in this program snippet to correctly display the auto's type.
A.myAuto.displayInfo()
B.myAuto.super.displayInfo()
C.myAuto.super.super.displayInfo()
D.This cannot be done unless the Auto class overrides the displayInfo method.

A.myAuto.displayInfo()
B.myAuto.super.displayInfo()
C.myAuto.super.super.displayInfo()
D.This cannot be done unless the Auto class overrides the displayInfo method.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
39
Suppose the class Message is partially defined as shown below: 
A subclass of Message, Excitedimessage, is defined that will behave like Message, except that it will add two exclamation points to the end of the message. Sample code that uses Excitedilessage is shown below:

Which ExcitedMessage constructor will give this behavior?
A)
B)
C)
D)

A subclass of Message, Excitedimessage, is defined that will behave like Message, except that it will add two exclamation points to the end of the message. Sample code that uses Excitedilessage is shown below:

Which ExcitedMessage constructor will give this behavior?
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following class hierarchy:
When an object of type Auto is constructed, what will be printed by the constructors from this inheritance hierarchy?
A.Vehicle Land Auto
B.Auto Land Vehicle
C.Land Auto Vehicle
D.Auto

A.Vehicle Land Auto
B.Auto Land Vehicle
C.Land Auto Vehicle
D.Auto
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
41
When the reserved word super is followed by a parenthesis, what does it indicate?
A.A call to a superclass method.
B.A call to a superclass constructor.
C.A call to a subclass method.
D.A call to a subclass constructor.
A.A call to a superclass method.
B.A call to a superclass constructor.
C.A call to a subclass method.
D.A call to a subclass constructor.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
42
What is the term used for a subclass that defines a method with the same name as a method in its superclass, but with different parameter types?
A.implementing
B.inheriting
C.overriding
D.overloading
A.implementing
B.inheriting
C.overriding
D.overloading
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
43
Consider the following code snippet:
Which of the following statements is correct?
A.The Motorcycle class's setVehicleClass method overrides the Vehicle class's setVehicleClass method.
B.The Vehicle class's setVehicleClass method overrides the Motorcycle class's setVehicleClass method.
C.The Motorcycle class's setVehicleClass method overloads the Vehicle class's setVehicleClass method.
D.The Vehicle class's setVehicleClass method overloads the Motorcycle class's setVehicleClass method.

A.The Motorcycle class's setVehicleClass method overrides the Vehicle class's setVehicleClass method.
B.The Vehicle class's setVehicleClass method overrides the Motorcycle class's setVehicleClass method.
C.The Motorcycle class's setVehicleClass method overloads the Vehicle class's setVehicleClass method.
D.The Vehicle class's setVehicleClass method overloads the Motorcycle class's setVehicleClass method.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
44
Consider the following code snippet that appears in a subclass:
Which of the following statements is true?
A)This method will call itself.
B)This method calls a public method in its subclass.
C)This method calls a private method in its superclass
D)This method calls a public method in its superclass.

A)This method will call itself.
B)This method calls a public method in its subclass.
C)This method calls a private method in its superclass
D)This method calls a public method in its superclass.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
45
When the reserved word super is followed by a period and a method name, what does it indicate?
A.A call to a superclass method.
B.A call to a superclass constructor.
C.A call to a subclass method.
D.A call to a subclass constructor.
A.A call to a superclass method.
B.A call to a superclass constructor.
C.A call to a subclass method.
D.A call to a subclass constructor.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
46
Consider the following code snippet:
What does this code do?
A.It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.
B.It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Motorcycle class.
D.It attempts to access directly an instance variable of the Vehicle superclass rather than using a constructor or an accessor.

A.It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.
B.It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Motorcycle class.
D.It attempts to access directly an instance variable of the Vehicle superclass rather than using a constructor or an accessor.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
47
Which of the following statements is true about using the reserved word super to call a superclass constructor?
A)The call must use the keyword super followed by a period and a method name.
B)The call must use the keyword super with no arguments.
C)The call must be the last line of the subclass constructor.
D)The call must be the first line of the subclass constructor.
A)The call must use the keyword super followed by a period and a method name.
B)The call must use the keyword super with no arguments.
C)The call must be the last line of the subclass constructor.
D)The call must be the first line of the subclass constructor.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
48
In Java, if you forget to call a superclass constructor explicitly in the constructor of a subclass, what will happen?
A.The code will not compile.
B.The default constructor (the one with no arguments) of the superclass will be invoked automatically.
C.The subclass will be constructed without invoking a constructor for the superclass.
D.The subclass object will be given a value of null.
A.The code will not compile.
B.The default constructor (the one with no arguments) of the superclass will be invoked automatically.
C.The subclass will be constructed without invoking a constructor for the superclass.
D.The subclass object will be given a value of null.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
49
Consider the classes shown below:
A.Methods 1 and 2 only
B.Method 2 only
C.Methods 2 and 3 only
D.Methods 1, 2, and 3

A.Methods 1 and 2 only
B.Method 2 only
C.Methods 2 and 3 only
D.Methods 1, 2, and 3
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
50
In Java, if you define two methods that have the same but different parameter types, the compiler will not complain. Why not?
A.The compiler will use only the most recent method definition.
B.The compiler considers the two methods to be completely unrelated.
C.The compiler cannot detect the difference between the two methods.
D.The compiler will silently link the two methods through inheritance.
A.The compiler will use only the most recent method definition.
B.The compiler considers the two methods to be completely unrelated.
C.The compiler cannot detect the difference between the two methods.
D.The compiler will silently link the two methods through inheritance.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
51
Consider the following code snippet:
Which of the following statements is correct?
A.The Auto class overrides the setVehicleClass method.
B.The Vehicle class overrides the setVehicleClass method.
C.The Auto class overloads the setVehicleClass method.
D.The Vehicle class overloads the setVehicleClass method.

A.The Auto class overrides the setVehicleClass method.
B.The Vehicle class overrides the setVehicleClass method.
C.The Auto class overloads the setVehicleClass method.
D.The Vehicle class overloads the setVehicleClass method.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
52
Consider the following code snippet:
What does this code do?
A.It invokes the constructor of the Vehicle class from within the constructor of the Auto class.
B.It invokes the constructor of the Auto class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Auto class.
D.This code will not compile.

A.It invokes the constructor of the Vehicle class from within the constructor of the Auto class.
B.It invokes the constructor of the Auto class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Auto class.
D.This code will not compile.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
53
Consider the following code snippet:
A.The Vehicle class constructor would invoke the constructor of the Motorcycle class with no parameters.
B.The Motorcycle class constructor would invoke the constructor of the Vehicle class with a parameter value of 0.
C.The Motorcycle class constructor would invoke the constructor of the Vehicle class with no parameters.
D.This code would not compile.

A.The Vehicle class constructor would invoke the constructor of the Motorcycle class with no parameters.
B.The Motorcycle class constructor would invoke the constructor of the Vehicle class with a parameter value of 0.
C.The Motorcycle class constructor would invoke the constructor of the Vehicle class with no parameters.
D.This code would not compile.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
54
If a subclass defines the same method name and the same parameter types for a method that appears in its superclass, which statement is true?
A)the subclass method overloads the superclass method.
B)the subclass method overrides the superclass method.
C)the subclass has implemented the method on behalf of the superclass.
D)a compiler error will occur.
A)the subclass method overloads the superclass method.
B)the subclass method overrides the superclass method.
C)the subclass has implemented the method on behalf of the superclass.
D)a compiler error will occur.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
55
Consider the classes shown below:
A.Method 1 only
B.Methods 2 and 3 only
C.Methods 1 and 2 only
D.Methods 1, 2, and 3

A.Method 1 only
B.Methods 2 and 3 only
C.Methods 1 and 2 only
D.Methods 1, 2, and 3
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
56
Consider the following code snippet:
Which of the following statements is NOT correct?
A.An object of type Motorcycle can call the setVehicleClass method of the Vehicle class on itself.
B.An object of type Vehicle can call the setModelName method on itself.
C.The Motorcycle class's SetVehicleClass method overrides the Vehicle class's setVehicleClass method.
D.An object of type Motorcycle can call the setVehicleClass method of the Motorcycle class on itself.

A.An object of type Motorcycle can call the setVehicleClass method of the Vehicle class on itself.
B.An object of type Vehicle can call the setModelName method on itself.
C.The Motorcycle class's SetVehicleClass method overrides the Vehicle class's setVehicleClass method.
D.An object of type Motorcycle can call the setVehicleClass method of the Motorcycle class on itself.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
57
Which statement is true about a subclass that uses the same method name but different parameter types for a method that appears in its superclass?
A)the subclass method has overloaded its superclass's method.
B)the subclass method has overridden its superclass's method.
C)the subclass has implemented its superclass's method.
D)a compiler error will occur.
A)the subclass method has overloaded its superclass's method.
B)the subclass method has overridden its superclass's method.
C)the subclass has implemented its superclass's method.
D)a compiler error will occur.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
58
Consider the following code snippet:
What does this code do?
A.It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.
B.It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Motorcycle class.
D.This code will not compile.

A.It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.
B.It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Motorcycle class.
D.This code will not compile.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
59
Consider the following code snippet:
What does this code do?
A.It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.
B.It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Motorcycle class.
D.This code will not compile.

A.It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.
B.It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class.
C.It invokes a private method of the Vehicle class from within a method of the Motorcycle class.
D.This code will not compile.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
60
Consider the following code snippet:
Which of the following statements is correct?
A.An object of type Programmer can call the setDepartment method of the Employee class on itself.
B.An object of type Employee can call the setProjectName method on itself.
C.The Employee class's setDepartment method overrides the Programmer class's setDepartment method.
D.An object of type Employee can call the setDepartment method of the Programmer class on itself.

A.An object of type Programmer can call the setDepartment method of the Employee class on itself.
B.An object of type Employee can call the setProjectName method on itself.
C.The Employee class's setDepartment method overrides the Programmer class's setDepartment method.
D.An object of type Employee can call the setDepartment method of the Programmer class on itself.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
61
To ensure that an instance variable can only be accessed by the class that declared it, how should the variable be declared?
A.public
B.private
C.protected
D.final
A.public
B.private
C.protected
D.final
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
62
With a few exceptions, what access should instance variables of classes always have?
A.final
B.private
C.public
D.protected
A.final
B.private
C.public
D.protected
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
63
Which of the following statements about abstract methods is true?
A)An abstract method has a name, parameters, and a return type, but no code in the body of the method.
B)An abstract method has parameters, a return type, and code in its body, but has no defined name.
C)An abstract method has a name, a return type, and code in its body, but has no parameters.
D)An abstract method has only a name and a return type, but no parameters or code in its body.
A)An abstract method has a name, parameters, and a return type, but no code in the body of the method.
B)An abstract method has parameters, a return type, and code in its body, but has no defined name.
C)An abstract method has a name, a return type, and code in its body, but has no parameters.
D)An abstract method has only a name and a return type, but no parameters or code in its body.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
64
What reserved word in a method definition ensures that subclasses cannot override the method?
A.abstract
B.anonymous
C.final
D.static
A.abstract
B.anonymous
C.final
D.static
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
65
Consider the following code snippet:
If the Programmer class inherits from the Employee class, and only the Employee class has an implementation of the increaseSalary method, which statement is correct?
A.The increaseSalary method call will cause a run-time error.
B.The increaseSalary method of the Employee class will be executed.
C.The Programmer class is required to provide an implementation of the increaseSalary method.
D.Programmer objects must be cast to Employee objects before the method call can me made.

A.The increaseSalary method call will cause a run-time error.
B.The increaseSalary method of the Employee class will be executed.
C.The Programmer class is required to provide an implementation of the increaseSalary method.
D.Programmer objects must be cast to Employee objects before the method call can me made.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
66
If a class has an abstract method, which of the following statements is NOT true?
A)You can construct an object from this class.
B)You can have an object reference whose type is this class.
C)You can inherit from this class.
D)All non-abstract subclasses of this class must implement this method.
A)You can construct an object from this class.
B)You can have an object reference whose type is this class.
C)You can inherit from this class.
D)All non-abstract subclasses of this class must implement this method.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
67
Consider the following code snippet: 
You wish to create a concrete subclass named PolisherHachine. Which of the following is the correct way to declare this subclass?
A)
B)
C)
D)

You wish to create a concrete subclass named PolisherHachine. Which of the following is the correct way to declare this subclass?
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
68
Consider the following code snippet:
Which statement is true about the accessibility of data in the numberAxles variable?
A)It is only accessible by the Vehicle class's methods and by all of its subclasses
B)It is only accessible by the Vehicle class's methods, by all of its subclasses, and by methods in classes within the same package.
C)It is only accessible by the Vehicle class's methods.
D)It is accessible by any class.

A)It is only accessible by the Vehicle class's methods and by all of its subclasses
B)It is only accessible by the Vehicle class's methods, by all of its subclasses, and by methods in classes within the same package.
C)It is only accessible by the Vehicle class's methods.
D)It is accessible by any class.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
69
Consider the following class hierarchy:
Which of the following code fragments is NOT valid in Java?
A.Vehicle myAuto = new Auto("sedan");
B.LandVehicle myAuto = new Auto("sedan");
C.Auto myAuto = new Auto("sedan");
D.LandVehicle myAuto = new Vehicle("sedan");

A.Vehicle myAuto = new Auto("sedan");
B.LandVehicle myAuto = new Auto("sedan");
C.Auto myAuto = new Auto("sedan");
D.LandVehicle myAuto = new Vehicle("sedan");
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
70
The term for a class from which you cannot create objects is
A.Abstract class.
B.Concrete class.
C.Non-inheritable class.
D.Superclass.
A.Abstract class.
B.Concrete class.
C.Non-inheritable class.
D.Superclass.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
71
Consider the following code snippet:
Assume that the Auto class inherits from the Vehicle class, and both classes have an implementation of the moveForward method with the same set of parameters and the same return type.The process for determining which class's moveForward method to execute is called ____.
A.inheritance disambiguation.
B.inheritance hierarchy.
C.dynamic inheritance.
D.dynamic method lookup.

A.inheritance disambiguation.
B.inheritance hierarchy.
C.dynamic inheritance.
D.dynamic method lookup.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
72
In designing an inheritance hierarchy it is helpful first to list classes that are part of the hierarchy and then organize those classes via an inheritance diagram.Once this has been done, what is the next step in the design?
A.Determine common responsibilities among the classes.
B.Decide which methods should be overridden.
C.Declare the public interface of each class.
D.Define and implement constructors and methods.
A.Determine common responsibilities among the classes.
B.Decide which methods should be overridden.
C.Declare the public interface of each class.
D.Define and implement constructors and methods.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
73
What reserved word in a class definition ensures that subclasses cannot be created from the class?
A.abstract
B.anonymous
C.final
D.static
A.abstract
B.anonymous
C.final
D.static
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
74
When declared as protected, which statement is true about the access to data in an object?
A)The data is accessible only by that class's methods and by all of its subclasses
B)The data is accessible only by that class's methods, by all of its subclasses, and by methods in classes within the same package.
C)The data is accessible only by that class's methods.
D)The data is accessible by any class.
A)The data is accessible only by that class's methods and by all of its subclasses
B)The data is accessible only by that class's methods, by all of its subclasses, and by methods in classes within the same package.
C)The data is accessible only by that class's methods.
D)The data is accessible by any class.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
75
Consider the following code snippet:
If the Auto class inherits from the Vehicle class, and both classes have an implementation of the moveForward method with the same set of parameters and the same return type, which statement is correct?
A.The moveForward method of the Auto class will be executed.
B.The moveForward method of the Vehicle class will be executed.
C.You must specify in the code which class's moveForward method is to be used.
D.It is not possible to determine which class's method is called.

A.The moveForward method of the Auto class will be executed.
B.The moveForward method of the Vehicle class will be executed.
C.You must specify in the code which class's moveForward method is to be used.
D.It is not possible to determine which class's method is called.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
76
Which of the following is true regarding inheritance?
A)When creating a subclass, all methods of the superclass must be overridden.
B)When creating a subclass, no methods of a superclass can be overridden.
C)A superclass can force a programmer to override a method in any subclass created from it.
D)A superclass cannot prevent a programmer from overriding a method in any subclass created from it.
A)When creating a subclass, all methods of the superclass must be overridden.
B)When creating a subclass, no methods of a superclass can be overridden.
C)A superclass can force a programmer to override a method in any subclass created from it.
D)A superclass cannot prevent a programmer from overriding a method in any subclass created from it.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
77
Suppose the abstract class Message is defined below
A concrete subclass of Message, called FrenchMessage, is defined.Which methods must FrenchMessage define?
A.translate() only
B.getMessage() only
C.The FrenchMessage constructor and translate() only
D.The FrenchMessage constructor, getMessage(), and translate()

A.translate() only
B.getMessage() only
C.The FrenchMessage constructor and translate() only
D.The FrenchMessage constructor, getMessage(), and translate()
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
78
Consider the following code snippet:
Assume that the Auto class inherits from the Vehicle class, and both classes have an implementation of the moveForward method with the same set of parameters and the same return type.What determines which class's moveForward method is to be executed?
A.the actual object type.
B.the variable's type.
C.the hierarchy of the classes.
D.it is not possible to determine which method is executed.

A.the actual object type.
B.the variable's type.
C.the hierarchy of the classes.
D.it is not possible to determine which method is executed.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
79
Which of the following statements about classes is true?
A)You can create an object from a class declared with the keyword final.
B)You can override methods in a class declared with the keyword final.
C)You can extend a class declared with the keyword final.
D)You can create subclasses from a class declared with the keyword final.
A)You can create an object from a class declared with the keyword final.
B)You can override methods in a class declared with the keyword final.
C)You can extend a class declared with the keyword final.
D)You can create subclasses from a class declared with the keyword final.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
80
Which of the following statements about classes is true?
A)You can create an object from a concrete class, but not from an abstract class.
B)You can create an object from an abstract class, but not from a concrete class.
C)You cannot have an object reference whose type is an abstract class.
D)You cannot create subclasses from abstract classes.
A)You can create an object from a concrete class, but not from an abstract class.
B)You can create an object from an abstract class, but not from a concrete class.
C)You cannot have an object reference whose type is an abstract class.
D)You cannot create subclasses from abstract classes.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck