Deck 9: Inheritance

Full screen (f)
exit full mode
Question
Consider the classes shown below: public class Parent
{
Public void doSomething(){/* Implementation not shown */}
}
Public class Child extends Parent
{
Public void doAnotherThing(){/* Implementation not shown */}
}
Which lines in the following code will compile without error?
Child kid = new Child();
Kid)doSomething(); // line 1
Kid)doAnotherThing(); // line 2

A) Line 1 only
B) Line 2 only
C) Lines 1 and 2
D) Neither line will compile without error
Use Space or
up arrow
down arrow
to flip the card.
Question
Suppose the class Message is partially defined as shown below public class Message
{
Private String value;
Public Message(String initial)
{
Value = initial;
}
Public String getMessage()
{
Return value;
}
}
A subclass of Message, ExcitedMessage, 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 ExcitedMessage is shown below.
ExcitedMessage greeting = new ExcitedMessage("Hello");
System.out.print(greeting.getMessage());
// will print "Hello!!"
Which ExcitedMessage constructor will give this behavior?

A) public ExcitedMessage(String line) {
Super(line + "!!");
}
B) public ExcitedMessage(String line) {
Value = line + "!!";
}
C) public ExcitedMessage(String line) {
Line = line + "!!";
Super(line);
}
D) public ExcitedMessage(String line) {
New Message(line + "!!");
}
Question
Consider the following inheritance hierarchy diagram: <strong>Consider the following inheritance hierarchy diagram:   Which of the following statements is correct?</strong> 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. <div style=padding-top: 35px> 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.
Question
A class that represents a more specific entity in an inheritance hierarchy is called a/an ____.

A) Default class
B) Superclass
C) Subclass.
D) Inheritance class.
Question
Consider the hierarchy of classes shown below. <strong>Consider the hierarchy of classes shown below.   What is the superclass of the class TelevisionShow?</strong> A) Object B) Comedy C) RealityShow D) This class has no superclass <div style=padding-top: 35px> What is the superclass of the class TelevisionShow?

A) Object
B) Comedy
C) RealityShow
D) This class has no superclass
Question
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.
Question
Consider the following inheritance hierarchy diagram: <strong>Consider the following inheritance hierarchy diagram:   Which of the following statements is correct?</strong> 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. <div style=padding-top: 35px> 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.
Question
Consider the classes shown below: public class Parent
{
Private int value = 100;
Public int getValue()
{
Return value;
}
}
Public class Child extends Parent
{
Private int value;
Public Child(int number)
{
Value = number;
}
}
What is the output of the following lines of code?
Child kid = new Child(-14);
Parent adult = new Parent();
System.out.println(kid.getValue() + " "
+ adult.getValue());

A) 100 100
B) -14 100
C) -14 -14
D) 100 -14
Question
Suppose the class Value is partially defined below public class Value
{
Private int number;
Public int getValue()
{
Return number;
}
}
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;
Question
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
Question
Consider the classes shown below: public class Parent
{
Private int value = 100;
Public int getValue()
{
Return value;
}
}
Public class Child extends Parent
{
Private int value;
Public Child(int number)
{
Value = number;
}
}
What is the output of the following lines of code?
Child kid = new Child(-14);
Parent kid2 = new Child(21);
System.out.println(kid.getValue() + " "
+ kid2.getValue());

A) 100 100
B) -14 21
C) 21 21
D) -14 100
Question
Insert the missing code in the following code fragment. This fragment is intended to call the Vehicle class's method. public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle()
{
_______________;
}
}

A) Motorcyle.setVehicleClass(2.0);
B) Vehicle.setVehicleClass(2.0);
C) this;setVehicleClass(2.0);
D) setVehicleClass(2.0);
Question
Consider the hierarchy of classes shown below. <strong>Consider the hierarchy of classes shown below.   Which represent valid class headers that would be found in this hierarchy?</strong> A) public class ScriptedShow extends TelevisionShow {. . . public class Comedy extends ScriptedShow {. . . B) public class TelevisionShow extends ScriptedShow {. . . public class ScriptedShow extends Comedy {. . . C) public class Drama extends TelevisionShow {. . . public class Comedy extends Drama {. . . D) public class ScriptedShow extends RealityShow {. . . public class RealityShow extends ScriptedShow {. . . <div style=padding-top: 35px> Which represent valid class headers that would be found in this hierarchy?

A) public class ScriptedShow extends TelevisionShow {. . . public class Comedy extends ScriptedShow {. . .
B) public class TelevisionShow extends ScriptedShow {. . . public class ScriptedShow extends Comedy {. . .
C) public class Drama extends TelevisionShow {. . . public class Comedy extends Drama {. . .
D) public class ScriptedShow extends RealityShow {. . . public class RealityShow extends ScriptedShow {. . .
Question
Consider the classes shown below: public class Parent
{
Private int value = 100;
Public int getValue()
{
Return value;
}
}
Public class Child extends Parent
{
Private int value;
Public Child(int number)
{
Value = number;
}
}
What is the output of the following lines of code?
Child kid = new Child(-14);
Child kid2 = new Child(21);
System.out.println(kid.getValue() + " "
+ kid2.getValue());

A) -14 21
B) 21 21
C) 21 100
D) 100 100
Question
Consider the hierarchy of classes shown below. <strong>Consider the hierarchy of classes shown below.   What is the superclass of the class ScriptedShow?</strong> A) Comedy B) RealityShow C) Object D) TelevisionShow <div style=padding-top: 35px> What is the superclass of the class ScriptedShow?

A) Comedy
B) RealityShow
C) Object
D) TelevisionShow
Question
Consider the classes shown below: public class Parent
{
Public void doSomething(){/* Implementation not shown */}
}
Public class Child extends Parent
{
Public void doAnotherThing(){/* Implementation not shown */}
}
Which lines in the following code will compile without error?
Parent kid = new Child();
Kid)doSomething(); // line 1
Kid)doAnotherThing(); // line 2

A) Line 1 only
B) Line 2 only
C) Lines 1 and 2
D) Neither line will compile without error
Question
Insert the missing code in the following code fragment. This fragment is intended to call the Vessel class's method. public class Vessel
{
) . .
Public void set VesselClass(double vesselLength)
{
) . .
}
}
Public class SpeedBoat extends Vessel
{
) . .
Public SpeedBoat()
{
_______________;
}
}

A) SpeedBoat.vesselLength(26.0);
B) Vessel.vesselLength(26.0);
C) this;vesselLength(26.0);
D) vesselLength(26.0);
Question
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
Question
A class that represents the most general entity in an inheritance hierarchy is called a/an ____.

A) Default class.
B) Superclass.
C) Subclass.
D) Inheritance class.
Question
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.
Question
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.
Question
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.
Question
To create a subclass, use the ____ keyword.

A) inherits
B) implements
C) interface
D) extends
Question
You are creating a Motorcycle class which is supposed to inherit from the Vehicle class. Which of the following class declaration statements will accomplish this?

A) public class Motorcycle inherits Vehicle
B) public class Motorcycle implements Vehicle
C) public class Motorcycle interfaces Vehicle
D) public class Motorcycle extends Vehicle
Question
Consider the following code snippet: public class Vessel
{
Private String manufacturer;
) . .
Public void setVesselClass(double engineRPM)
{
) . .
}
}
If a Speedboat class is created as a subclass of the Vessel class, which of the following statements is correct?

A) A Speedboat object inherits and can directly use both the instance variable manufacturer and the method setVesselClass.
B) A Speedboat object inherits and can directly use the instance variable manufacturer but not the method setVesselClass.
C) A Speedboat object inherits but cannot directly use either the instance variable manufacturer or the method setVesselClass.
D) A Speedboat object inherits and can directly use the method setVesselClass but cannot directly use the instance variable manufacturer.
Question
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.
Question
You are creating a Motorcycle class that is supposed to be a subclass of the Vehicle class. Which of the following class declaration statements will accomplish this?

A) public class Vehicle extends Motorcycle
B) public class Motorcycle extends Vehicle
C) public class Vehicle inherits Motorcycle
D) public class Motorcycle inherits Vehicle
Question
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
Question
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String displayInfo()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
) . .
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
) . .
}
Public String displayAutoType()
{
Return _____;
}
}
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()
Question
Which of the following indicates that the Motorcycle class is a subclass of the Vehicle class?

A) public class Motorcycle extends Vehicle
B) public class Motorcycle implements Vehicle
C) public class Vehicle extends Motorcycle
D) public class Vehicle implements Motorcycle
Question
Consider the following code snippet: public void deposit(double amount)
{
TransactionCount ++;
Super.deposit(amount);
}
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.
Question
Consider the following code snippet: public class Vehicle
{
Private String manufacturer;
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
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.
Question
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.
Question
Consider the following code snippet: public class Vessel
{
) . .
Public void setVesselAtrributes()
{
) . .
}
}
Public class Speedboat extends Vessel
{
) . .
Public void setVesselAtrributes()
{
) . .
}
}
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.
Question
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String displayInfo()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
Super(type);
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
_________;
}
}
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 the Auto declares an instance variable named type.
Question
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleAtrributes()
{
) . .
}
}
Public class Auto extends Vehicle
{
) . .
Public void setVehicleAtrributes()
{
) . .
}
}
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.
Question
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String displayInfo()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
Super(type);
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
Super(type);
}
}
You have written a program to use these classes, as shown in the following code snippet:
Public class VehicleTester
{
Public static void main(String[] args)
{
Auto myAuto = new Auto("sedan");
System.out.println("MyAuto type = " + ______);
}
}
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.
Question
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
Question
Which of the following indicates that a class named Class1 is a subclass of a class named Class2?

A) public class Class1 extends Class2
B) public class Class1 implements Class2
C) public class Class2 extends Class1
D) public class Class2 implements Class1
Question
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.
Question
Consider the following code snippet: public class Employee
{
) . .
Public void setDepartment(String deptName)
{
) . .
}
}
Public class Programmer extends Employee
{
) . .
Public void setProjectName(String projName)
{
) . .
}
Public void setDepartment(String deptName)
{
) . .
}
}
Which of the following statements is NOT correct?

A) The Programmer class can call the setDepartment method of the Employee class.
B) The Employee class can call the setProjectName method.
C) The Programmer class's setDepartment method overrides the Employee class's setDepartment method.
D) The Programmer class can call the setDepartment method of the Programmer class.
Question
Consider the following code snippet: public class Vessel
{
) . .
Public void setVesselClass(double numberAxles)
{
) . .
}
}
Public class Speedboat extends Vessel
{
) . .
Public void setVesselClass(double numberAxles)
{
) . .
}
}
Which of the following statements is correct?

A) The Speedboat class's setVesselClass method overrides the Vessel class's setVesselClass method.
B) The Vessel class's setVesselClass method overrides the Speedboat class's setVesselClass method.
C) The Speedboat class's setVesselClass method overloads the Vessel class's setVesselClass method.
D) The Vessel class's setVesselClass method overloads the Speedboat class's setVesselClass method.
Question
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Motorcycle extends Vehicle
{
) . .
Public void setModelName(String model)
{
) . .
}
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Which of the following statements is NOT correct?

A) The Motorcycle class can call the setVehicleClass method of the Vehicle class.
B) The Vehicle class can call the setModelName method.
C) The Motorcycle class's SetVehicleClass method overrides the Vehicle class's setVehicleClass method.
D) The Motorcycle class can call the setVehicleClass method of the Motorcycle class.
Question
If a subclass 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.
Question
Consider the following code snippet: public class Motorcycle extends Vehicle
{
Private String model;
) . .
Public Motorcycle(int numberAxles, String modelName)
{
Super(numberAxles);
Model = modelName;
}
}
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.
Question
If a subclass defines the same method name and the same parameter types for a method that appears in its superclass, ____.

A) the subclass method overloads the superclass method.
B) the subclass method overrides the superclass method.
C) the subclass has implemented its superclass's method.
D) a compiler error will occur.
Question
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Motorcycle extends Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Which of the following statements is correct? (I changed the wording below, because methods override methods. . .classes don't override methods)

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.
Question
Consider the classes shown below: public class Parent
{
Public void doSomething() // method 1
{ /* Implementation not shown */ }
}
Public class Child extends Parent
{
Public void doSomething(int n) // method 2
{ /* Implementation not shown */ }
Public void doSomething() // method 3
{ /* Implementation not shown */ }
}
If the variable kid is defined below, which version of the doSomething method can be called on the variable kid?
Child kid = new Child();

A) Methods 1 and 2 only
B) Method 2 only
C) Methods 2 and 3 only
D) Methods 1, 2, and 3
Question
Consider the following code snippet: public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle(int numberAxles)
{
Super(numberAxles); //line #1
}
}
If the line marked "//line #1" was missing, which of these statements would be correct?

A) The Motorcycle class constructor would invoke the constructor of the Vehicle class with no parameters.
B) The Vehicle class constructor would invoke the constructor of the Motorcycle class with no parameters.
C) The Motorcycle class constructor would invoke the constructor of the Vehicle class with a parameter value of 0.
D) This code would not compile.
Question
If a subclass contains a method with the same name as a method in its superclass, but with different parameter types, the subclass method is said to ____ the method of the superclass.

A) implement
B) inherit
C) override
D) overload
Question
Consider the following code snippet: public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle(int numberAxles)
{
Super.numberAxles;
}
}
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.
Question
Consider the classes shown below: public class Parent
{
Public void doSomething() // method 1
{ /* Implementation not shown */ }
}
Public class Child extends Parent {
Public void doSomething(int n) // method 2
{ /* Implementation not shown */ }
Public void doSomething() // method 3
{ /* Implementation not shown */ }
}
If the variable kid is defined below, which version of the doSomething method can be called on the variable kid?
Parent kid = new Child();

A) Method 1 only
B) Methods 2 and 3 only
C) Methods 1 and 2 only
D) Methods 1, 2, and 3
Question
Consider the following code snippet: public class Auto extends Vehicle
{
) . .
Public Auto(int numberAxles)
{
Super(numberAxles);
}
}
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.
Question
Consider the following code snippet: public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle(int numberAxles)
{
Super(numberAxles);
}
}
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.
Question
Consider the following code snippet: public class Motorcycle extends Vehicle
{
Private String model;
) . .
Public Motorcycle(int numberAxles, String modelName)
{
Model = modelName;
Super(numberAxles);
}
}
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.
Question
To override a superclass method in a subclass, the subclass method ____.

A) Must use a different method name.
B) Must use the same method name and the same parameter types.
C) Must use a different method name and the same parameter types.
D) Must use a different method name and different parameter types.
Question
Consider the following code snippet that appears in a subclass: public void deposit(double amount)
{
TransactionCount ++;
Deposit(amount);
}
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.
Question
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Auto extends Vehicle
{
) . .
Public void setVehicleClass(int numberAxles)
{
) . .
}
}
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.
Question
Which reserved word must be used to call a method of a superclass?

A) this
B) my
C) parent
D) super
Question
Consider the following code snippet: public class Employee
{
) . .
Public void setEmployeeDept(String deptNum)
{
) . .
}
}
Public class Programmer extends Employee
{
) . .
Public void setEmployeeDept(int deptNum)
{
) . .
}
}
Which of the following statements is correct?

A) The Programmer class overrides the setEmployeeDept method.
B) The Employee class overrides the setEmployeeDept method.
C) The Programmer class overloads the setEmployeeDept method.
D) The Employee class overloads the setEmployeeDept method.
Question
Consider the following code snippet: public abstract class Employee
{
Public abstract void setSalary();
) . .
}
You wish to create a concrete subclass named Programmer. Which of the following is the correct way to declare this subclass?

A) public class Programmer implements Employee
{
Public void setSalary() { . . . }
}
B) public class Programmer extends Employee
{
Void setSalary() { . . . }
}
C) public class Programmer implements Employee
{
Void setSalary() { . . . }
}
D) public class Programmer extends Employee
{
Public void setSalary() { . . . }
}
Question
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.
Question
A class that cannot be instantiated is called a/an ____.

A) Abstract class.
B) Anonymous class.
C) Concrete class.
D) Non-inheritable class.
Question
Consider the Counter class below. public class Counter
{
Public int count = 0;
Public int getCount()
{
Return count;
}
Public void increment()
{
Count++;
}
}
Using the class above and the variables declared below, what is the value of num1.equals(num2)?
Counter num1 = new Counter();
Counter num2 = new Counter();

A) true
B) false
C) nothing since equals is not defined for Counter
Question
Consider the following code snippet: Vehicle aVehicle = new Auto();
AVehicle.moveForward(200);
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. Which class's moveForward method is to be executed is determined by ____.

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.
Question
Consider the following code snippet: Employee anEmployee = new Programmer();
AnEmployee.increaseSalary(2500);
Assume that the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters and the same return type. Which class's increaseSalary method is to be executed is determined by ____.

A) the hierarchy of the classes.
B) the variable's type.
C) the actual object type.
D) it is not possible to determine which method is executed.
Question
Consider the classes shown below: public class Parent
{
Public int getValue()
{
Return 24;
}
Public void display()
{
System.out.print(getValue() + " ");
}
}
Public class Child extends Parent
{
Public int getValue()
{
Return -7;
}
}
Using the classes above, what is the output of the following lines of code?
Parent kid = new Child();
Parent adult = new Parent();
Kid)display();
Adult.display();

A) -7 24
B) 24 24
C) -7 -7
D) 24 -7
Question
Suppose the abstract class Message is defined below public abstract class Message {
Private String value;
Public Message(String initial)
{
Value = initial;
}
Public String getMessage()
{
Return value;
}
Public abstract String translate();
}
A concrete subclass of Message, 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()
Question
Consider the following code snippet: Vehicle aVehicle = new Auto();
AVehicle.moveForward(200);
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 lookup.
Question
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.
Question
A class from which you cannot create objects is called a/an ____.

A) Abstract class.
B) Concrete class.
C) Non-inheritable class.
D) Superclass.
Question
Consider the following code snippet: Employee anEmployee = new Programmer();
AnEmployee.increaseSalary(2500);
If the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters and the same return type, which statement is correct?

A) The increaseSalary method of the Programmer class will be executed.
B) The increaseSalary method of the Employee class will be executed.
C) You must specify in the code which class's increaseSalary method is to be used.
D) It is not possible to determine which class's method is called.
Question
Consider the classes shown below: public class Parent
{
Public int getValue()
{
Return 24;
}
Public void display()
{
System.out.print(getValue() + " ");
}
}
Public class Child extends Parent
{
Public int getValue()
{
Return -7;
}
}
Using the classes above, what is the output of the following lines of code?
Child kid = new Child();
Parent adult = new Parent();
Kid)display();
Adult.display();

A) 24 24
B) -7 -7
C) -7 24
D) 24 -7
Question
Consider the Counter class below. public class Counter
{
Public int count = 0;
Public int getCount()
{
Return count;
}
Public void increment()
{
Count++;
}
}
Using the class above and the variables declared below, what is the value of num1.equals(num2)?
Counter num1 = new Counter();
Counter num2 = num1;

A) true
B) false
C) nothing since equals is not defined for Counter
Question
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.
Question
Consider the Counter class below. public class Counter
{
Public int count = 0;
Public int getCount()
{
Return count;
}
Public void increment()
{
Count++;
}
}
Using the class above and the variable declared below, what is the value of num.toString()?
Counter num = new Counter();

A) a string with count's value
B) a string with num's type and hashcode
C) a string with count's type and hashcode
D) nothing since toString is not defined for Counter
Question
Consider the following code snippet: Vehicle aVehicle = new Auto();
AVehicle.moveForward(200);
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.
Question
Consider the following code snippet: public abstract class Machine
{
Public abstract void setRPMs();
) . .
}
You wish to create a concrete subclass named PolisherMachine. Which of the following is the correct way to declare this subclass?

A) public class PolisherMachine implements Machine
{
Public void setRPMs() { . . . }
}
B) public class PolisherMachine extends Machine
{
Void setRPMs() { . . . }
}
C) public class PolisherMachine implements Machine
{
Void setRPMs() { . . . }
}
D) public class PolisherMachine extends Machine
{
Public void setRPMs() { . . . }
}
Question
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.
Question
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String getType()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
) . .
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
) . .
}
}
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");
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/101
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Inheritance
1
Consider the classes shown below: public class Parent
{
Public void doSomething(){/* Implementation not shown */}
}
Public class Child extends Parent
{
Public void doAnotherThing(){/* Implementation not shown */}
}
Which lines in the following code will compile without error?
Child kid = new Child();
Kid)doSomething(); // line 1
Kid)doAnotherThing(); // line 2

A) Line 1 only
B) Line 2 only
C) Lines 1 and 2
D) Neither line will compile without error
C
2
Suppose the class Message is partially defined as shown below public class Message
{
Private String value;
Public Message(String initial)
{
Value = initial;
}
Public String getMessage()
{
Return value;
}
}
A subclass of Message, ExcitedMessage, 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 ExcitedMessage is shown below.
ExcitedMessage greeting = new ExcitedMessage("Hello");
System.out.print(greeting.getMessage());
// will print "Hello!!"
Which ExcitedMessage constructor will give this behavior?

A) public ExcitedMessage(String line) {
Super(line + "!!");
}
B) public ExcitedMessage(String line) {
Value = line + "!!";
}
C) public ExcitedMessage(String line) {
Line = line + "!!";
Super(line);
}
D) public ExcitedMessage(String line) {
New Message(line + "!!");
}
A
3
Consider the following inheritance hierarchy diagram: <strong>Consider the following inheritance hierarchy diagram:   Which of the following statements is correct?</strong> 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. 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
4
A class that represents a more specific entity in an inheritance hierarchy is called a/an ____.

A) Default class
B) Superclass
C) Subclass.
D) Inheritance class.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
5
Consider the hierarchy of classes shown below. <strong>Consider the hierarchy of classes shown below.   What is the superclass of the class TelevisionShow?</strong> A) Object B) Comedy C) RealityShow D) This class has no superclass What is the superclass of the class TelevisionShow?

A) Object
B) Comedy
C) RealityShow
D) This class has no superclass
Unlock Deck
Unlock for access to all 101 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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
7
Consider the following inheritance hierarchy diagram: <strong>Consider the following inheritance hierarchy diagram:   Which of the following statements is correct?</strong> 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. 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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
8
Consider the classes shown below: public class Parent
{
Private int value = 100;
Public int getValue()
{
Return value;
}
}
Public class Child extends Parent
{
Private int value;
Public Child(int number)
{
Value = number;
}
}
What is the output of the following lines of code?
Child kid = new Child(-14);
Parent adult = new Parent();
System.out.println(kid.getValue() + " "
+ adult.getValue());

A) 100 100
B) -14 100
C) -14 -14
D) 100 -14
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
9
Suppose the class Value is partially defined below public class Value
{
Private int number;
Public int getValue()
{
Return number;
}
}
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;
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
10
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
11
Consider the classes shown below: public class Parent
{
Private int value = 100;
Public int getValue()
{
Return value;
}
}
Public class Child extends Parent
{
Private int value;
Public Child(int number)
{
Value = number;
}
}
What is the output of the following lines of code?
Child kid = new Child(-14);
Parent kid2 = new Child(21);
System.out.println(kid.getValue() + " "
+ kid2.getValue());

A) 100 100
B) -14 21
C) 21 21
D) -14 100
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
12
Insert the missing code in the following code fragment. This fragment is intended to call the Vehicle class's method. public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle()
{
_______________;
}
}

A) Motorcyle.setVehicleClass(2.0);
B) Vehicle.setVehicleClass(2.0);
C) this;setVehicleClass(2.0);
D) setVehicleClass(2.0);
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
13
Consider the hierarchy of classes shown below. <strong>Consider the hierarchy of classes shown below.   Which represent valid class headers that would be found in this hierarchy?</strong> A) public class ScriptedShow extends TelevisionShow {. . . public class Comedy extends ScriptedShow {. . . B) public class TelevisionShow extends ScriptedShow {. . . public class ScriptedShow extends Comedy {. . . C) public class Drama extends TelevisionShow {. . . public class Comedy extends Drama {. . . D) public class ScriptedShow extends RealityShow {. . . public class RealityShow extends ScriptedShow {. . . Which represent valid class headers that would be found in this hierarchy?

A) public class ScriptedShow extends TelevisionShow {. . . public class Comedy extends ScriptedShow {. . .
B) public class TelevisionShow extends ScriptedShow {. . . public class ScriptedShow extends Comedy {. . .
C) public class Drama extends TelevisionShow {. . . public class Comedy extends Drama {. . .
D) public class ScriptedShow extends RealityShow {. . . public class RealityShow extends ScriptedShow {. . .
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
14
Consider the classes shown below: public class Parent
{
Private int value = 100;
Public int getValue()
{
Return value;
}
}
Public class Child extends Parent
{
Private int value;
Public Child(int number)
{
Value = number;
}
}
What is the output of the following lines of code?
Child kid = new Child(-14);
Child kid2 = new Child(21);
System.out.println(kid.getValue() + " "
+ kid2.getValue());

A) -14 21
B) 21 21
C) 21 100
D) 100 100
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
15
Consider the hierarchy of classes shown below. <strong>Consider the hierarchy of classes shown below.   What is the superclass of the class ScriptedShow?</strong> A) Comedy B) RealityShow C) Object D) TelevisionShow What is the superclass of the class ScriptedShow?

A) Comedy
B) RealityShow
C) Object
D) TelevisionShow
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
16
Consider the classes shown below: public class Parent
{
Public void doSomething(){/* Implementation not shown */}
}
Public class Child extends Parent
{
Public void doAnotherThing(){/* Implementation not shown */}
}
Which lines in the following code will compile without error?
Parent kid = new Child();
Kid)doSomething(); // line 1
Kid)doAnotherThing(); // line 2

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 101 flashcards in this deck.
Unlock Deck
k this deck
17
Insert the missing code in the following code fragment. This fragment is intended to call the Vessel class's method. public class Vessel
{
) . .
Public void set VesselClass(double vesselLength)
{
) . .
}
}
Public class SpeedBoat extends Vessel
{
) . .
Public SpeedBoat()
{
_______________;
}
}

A) SpeedBoat.vesselLength(26.0);
B) Vessel.vesselLength(26.0);
C) this;vesselLength(26.0);
D) vesselLength(26.0);
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
18
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
19
A class that represents the most general entity in an inheritance hierarchy is called a/an ____.

A) Default class.
B) Superclass.
C) Subclass.
D) Inheritance class.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
20
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
21
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.
Unlock Deck
Unlock for access to all 101 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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
23
To create a subclass, use the ____ keyword.

A) inherits
B) implements
C) interface
D) extends
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
24
You are creating a Motorcycle class which is supposed to inherit from the Vehicle class. Which of the following class declaration statements will accomplish this?

A) public class Motorcycle inherits Vehicle
B) public class Motorcycle implements Vehicle
C) public class Motorcycle interfaces Vehicle
D) public class Motorcycle extends Vehicle
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
25
Consider the following code snippet: public class Vessel
{
Private String manufacturer;
) . .
Public void setVesselClass(double engineRPM)
{
) . .
}
}
If a Speedboat class is created as a subclass of the Vessel class, which of the following statements is correct?

A) A Speedboat object inherits and can directly use both the instance variable manufacturer and the method setVesselClass.
B) A Speedboat object inherits and can directly use the instance variable manufacturer but not the method setVesselClass.
C) A Speedboat object inherits but cannot directly use either the instance variable manufacturer or the method setVesselClass.
D) A Speedboat object inherits and can directly use the method setVesselClass but cannot directly use the instance variable manufacturer.
Unlock Deck
Unlock for access to all 101 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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
27
You are creating a Motorcycle class that is supposed to be a subclass of the Vehicle class. Which of the following class declaration statements will accomplish this?

A) public class Vehicle extends Motorcycle
B) public class Motorcycle extends Vehicle
C) public class Vehicle inherits Motorcycle
D) public class Motorcycle inherits Vehicle
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
28
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
29
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String displayInfo()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
) . .
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
) . .
}
Public String displayAutoType()
{
Return _____;
}
}
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()
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following indicates that the Motorcycle class is a subclass of the Vehicle class?

A) public class Motorcycle extends Vehicle
B) public class Motorcycle implements Vehicle
C) public class Vehicle extends Motorcycle
D) public class Vehicle implements Motorcycle
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
31
Consider the following code snippet: public void deposit(double amount)
{
TransactionCount ++;
Super.deposit(amount);
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
32
Consider the following code snippet: public class Vehicle
{
Private String manufacturer;
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
33
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
34
Consider the following code snippet: public class Vessel
{
) . .
Public void setVesselAtrributes()
{
) . .
}
}
Public class Speedboat extends Vessel
{
) . .
Public void setVesselAtrributes()
{
) . .
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
35
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String displayInfo()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
Super(type);
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
_________;
}
}
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 the Auto declares an instance variable named type.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
36
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleAtrributes()
{
) . .
}
}
Public class Auto extends Vehicle
{
) . .
Public void setVehicleAtrributes()
{
) . .
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
37
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String displayInfo()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
Super(type);
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
Super(type);
}
}
You have written a program to use these classes, as shown in the following code snippet:
Public class VehicleTester
{
Public static void main(String[] args)
{
Auto myAuto = new Auto("sedan");
System.out.println("MyAuto type = " + ______);
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
38
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following indicates that a class named Class1 is a subclass of a class named Class2?

A) public class Class1 extends Class2
B) public class Class1 implements Class2
C) public class Class2 extends Class1
D) public class Class2 implements Class1
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
40
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
41
Consider the following code snippet: public class Employee
{
) . .
Public void setDepartment(String deptName)
{
) . .
}
}
Public class Programmer extends Employee
{
) . .
Public void setProjectName(String projName)
{
) . .
}
Public void setDepartment(String deptName)
{
) . .
}
}
Which of the following statements is NOT correct?

A) The Programmer class can call the setDepartment method of the Employee class.
B) The Employee class can call the setProjectName method.
C) The Programmer class's setDepartment method overrides the Employee class's setDepartment method.
D) The Programmer class can call the setDepartment method of the Programmer class.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
42
Consider the following code snippet: public class Vessel
{
) . .
Public void setVesselClass(double numberAxles)
{
) . .
}
}
Public class Speedboat extends Vessel
{
) . .
Public void setVesselClass(double numberAxles)
{
) . .
}
}
Which of the following statements is correct?

A) The Speedboat class's setVesselClass method overrides the Vessel class's setVesselClass method.
B) The Vessel class's setVesselClass method overrides the Speedboat class's setVesselClass method.
C) The Speedboat class's setVesselClass method overloads the Vessel class's setVesselClass method.
D) The Vessel class's setVesselClass method overloads the Speedboat class's setVesselClass method.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
43
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Motorcycle extends Vehicle
{
) . .
Public void setModelName(String model)
{
) . .
}
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Which of the following statements is NOT correct?

A) The Motorcycle class can call the setVehicleClass method of the Vehicle class.
B) The Vehicle class can call the setModelName method.
C) The Motorcycle class's SetVehicleClass method overrides the Vehicle class's setVehicleClass method.
D) The Motorcycle class can call the setVehicleClass method of the Motorcycle class.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
44
If a subclass 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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
45
Consider the following code snippet: public class Motorcycle extends Vehicle
{
Private String model;
) . .
Public Motorcycle(int numberAxles, String modelName)
{
Super(numberAxles);
Model = modelName;
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
46
If a subclass defines the same method name and the same parameter types for a method that appears in its superclass, ____.

A) the subclass method overloads the superclass method.
B) the subclass method overrides the superclass method.
C) the subclass has implemented its superclass's method.
D) a compiler error will occur.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
47
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Motorcycle extends Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Which of the following statements is correct? (I changed the wording below, because methods override methods. . .classes don't override methods)

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 101 flashcards in this deck.
Unlock Deck
k this deck
48
Consider the classes shown below: public class Parent
{
Public void doSomething() // method 1
{ /* Implementation not shown */ }
}
Public class Child extends Parent
{
Public void doSomething(int n) // method 2
{ /* Implementation not shown */ }
Public void doSomething() // method 3
{ /* Implementation not shown */ }
}
If the variable kid is defined below, which version of the doSomething method can be called on the variable kid?
Child kid = new Child();

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 101 flashcards in this deck.
Unlock Deck
k this deck
49
Consider the following code snippet: public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle(int numberAxles)
{
Super(numberAxles); //line #1
}
}
If the line marked "//line #1" was missing, which of these statements would be correct?

A) The Motorcycle class constructor would invoke the constructor of the Vehicle class with no parameters.
B) The Vehicle class constructor would invoke the constructor of the Motorcycle class with no parameters.
C) The Motorcycle class constructor would invoke the constructor of the Vehicle class with a parameter value of 0.
D) This code would not compile.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
50
If a subclass contains a method with the same name as a method in its superclass, but with different parameter types, the subclass method is said to ____ the method of the superclass.

A) implement
B) inherit
C) override
D) overload
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
51
Consider the following code snippet: public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle(int numberAxles)
{
Super.numberAxles;
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
52
Consider the classes shown below: public class Parent
{
Public void doSomething() // method 1
{ /* Implementation not shown */ }
}
Public class Child extends Parent {
Public void doSomething(int n) // method 2
{ /* Implementation not shown */ }
Public void doSomething() // method 3
{ /* Implementation not shown */ }
}
If the variable kid is defined below, which version of the doSomething method can be called on the variable kid?
Parent kid = new Child();

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 101 flashcards in this deck.
Unlock Deck
k this deck
53
Consider the following code snippet: public class Auto extends Vehicle
{
) . .
Public Auto(int numberAxles)
{
Super(numberAxles);
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
54
Consider the following code snippet: public class Motorcycle extends Vehicle
{
) . .
Public Motorcycle(int numberAxles)
{
Super(numberAxles);
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
55
Consider the following code snippet: public class Motorcycle extends Vehicle
{
Private String model;
) . .
Public Motorcycle(int numberAxles, String modelName)
{
Model = modelName;
Super(numberAxles);
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
56
To override a superclass method in a subclass, the subclass method ____.

A) Must use a different method name.
B) Must use the same method name and the same parameter types.
C) Must use a different method name and the same parameter types.
D) Must use a different method name and different parameter types.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
57
Consider the following code snippet that appears in a subclass: public void deposit(double amount)
{
TransactionCount ++;
Deposit(amount);
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
58
Consider the following code snippet: public class Vehicle
{
) . .
Public void setVehicleClass(double numberAxles)
{
) . .
}
}
Public class Auto extends Vehicle
{
) . .
Public void setVehicleClass(int numberAxles)
{
) . .
}
}
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
59
Which reserved word must be used to call a method of a superclass?

A) this
B) my
C) parent
D) super
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
60
Consider the following code snippet: public class Employee
{
) . .
Public void setEmployeeDept(String deptNum)
{
) . .
}
}
Public class Programmer extends Employee
{
) . .
Public void setEmployeeDept(int deptNum)
{
) . .
}
}
Which of the following statements is correct?

A) The Programmer class overrides the setEmployeeDept method.
B) The Employee class overrides the setEmployeeDept method.
C) The Programmer class overloads the setEmployeeDept method.
D) The Employee class overloads the setEmployeeDept method.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
61
Consider the following code snippet: public abstract class Employee
{
Public abstract void setSalary();
) . .
}
You wish to create a concrete subclass named Programmer. Which of the following is the correct way to declare this subclass?

A) public class Programmer implements Employee
{
Public void setSalary() { . . . }
}
B) public class Programmer extends Employee
{
Void setSalary() { . . . }
}
C) public class Programmer implements Employee
{
Void setSalary() { . . . }
}
D) public class Programmer extends Employee
{
Public void setSalary() { . . . }
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
62
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
63
A class that cannot be instantiated is called a/an ____.

A) Abstract class.
B) Anonymous class.
C) Concrete class.
D) Non-inheritable class.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
64
Consider the Counter class below. public class Counter
{
Public int count = 0;
Public int getCount()
{
Return count;
}
Public void increment()
{
Count++;
}
}
Using the class above and the variables declared below, what is the value of num1.equals(num2)?
Counter num1 = new Counter();
Counter num2 = new Counter();

A) true
B) false
C) nothing since equals is not defined for Counter
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
65
Consider the following code snippet: Vehicle aVehicle = new Auto();
AVehicle.moveForward(200);
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. Which class's moveForward method is to be executed is determined by ____.

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 101 flashcards in this deck.
Unlock Deck
k this deck
66
Consider the following code snippet: Employee anEmployee = new Programmer();
AnEmployee.increaseSalary(2500);
Assume that the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters and the same return type. Which class's increaseSalary method is to be executed is determined by ____.

A) the hierarchy of the classes.
B) the variable's type.
C) the actual object type.
D) it is not possible to determine which method is executed.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
67
Consider the classes shown below: public class Parent
{
Public int getValue()
{
Return 24;
}
Public void display()
{
System.out.print(getValue() + " ");
}
}
Public class Child extends Parent
{
Public int getValue()
{
Return -7;
}
}
Using the classes above, what is the output of the following lines of code?
Parent kid = new Child();
Parent adult = new Parent();
Kid)display();
Adult.display();

A) -7 24
B) 24 24
C) -7 -7
D) 24 -7
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
68
Suppose the abstract class Message is defined below public abstract class Message {
Private String value;
Public Message(String initial)
{
Value = initial;
}
Public String getMessage()
{
Return value;
}
Public abstract String translate();
}
A concrete subclass of Message, 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()
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
69
Consider the following code snippet: Vehicle aVehicle = new Auto();
AVehicle.moveForward(200);
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 lookup.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
70
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
71
A class from which you cannot create objects is called a/an ____.

A) Abstract class.
B) Concrete class.
C) Non-inheritable class.
D) Superclass.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
72
Consider the following code snippet: Employee anEmployee = new Programmer();
AnEmployee.increaseSalary(2500);
If the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters and the same return type, which statement is correct?

A) The increaseSalary method of the Programmer class will be executed.
B) The increaseSalary method of the Employee class will be executed.
C) You must specify in the code which class's increaseSalary 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 101 flashcards in this deck.
Unlock Deck
k this deck
73
Consider the classes shown below: public class Parent
{
Public int getValue()
{
Return 24;
}
Public void display()
{
System.out.print(getValue() + " ");
}
}
Public class Child extends Parent
{
Public int getValue()
{
Return -7;
}
}
Using the classes above, what is the output of the following lines of code?
Child kid = new Child();
Parent adult = new Parent();
Kid)display();
Adult.display();

A) 24 24
B) -7 -7
C) -7 24
D) 24 -7
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
74
Consider the Counter class below. public class Counter
{
Public int count = 0;
Public int getCount()
{
Return count;
}
Public void increment()
{
Count++;
}
}
Using the class above and the variables declared below, what is the value of num1.equals(num2)?
Counter num1 = new Counter();
Counter num2 = num1;

A) true
B) false
C) nothing since equals is not defined for Counter
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
75
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
76
Consider the Counter class below. public class Counter
{
Public int count = 0;
Public int getCount()
{
Return count;
}
Public void increment()
{
Count++;
}
}
Using the class above and the variable declared below, what is the value of num.toString()?
Counter num = new Counter();

A) a string with count's value
B) a string with num's type and hashcode
C) a string with count's type and hashcode
D) nothing since toString is not defined for Counter
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
77
Consider the following code snippet: Vehicle aVehicle = new Auto();
AVehicle.moveForward(200);
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
78
Consider the following code snippet: public abstract class Machine
{
Public abstract void setRPMs();
) . .
}
You wish to create a concrete subclass named PolisherMachine. Which of the following is the correct way to declare this subclass?

A) public class PolisherMachine implements Machine
{
Public void setRPMs() { . . . }
}
B) public class PolisherMachine extends Machine
{
Void setRPMs() { . . . }
}
C) public class PolisherMachine implements Machine
{
Void setRPMs() { . . . }
}
D) public class PolisherMachine extends Machine
{
Public void setRPMs() { . . . }
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
79
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
80
Consider the following class hierarchy: public class Vehicle
{
Private String type;
Public Vehicle(String type)
{
This.type = type;
}
Public String getType()
{
Return type;
}
}
Public class LandVehicle extends Vehicle
{
Public LandVehicle(String type)
{
) . .
}
}
Public class Auto extends LandVehicle
{
Public Auto(String type)
{
) . .
}
}
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");
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 101 flashcards in this deck.