CSI II Quiz 6

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

9) A class that cannot be instantiated is called a/an a) Abstract class b) Anonymous class. c) Concrete class. d) Non-inheritable.

a) Abstract class

Which of the following statements about abstract methods is true? a) An abstract method has a name, parameters, and return type, but no code in the body of the method. b) An abstract method has parameters, a returned type, and code in its body coma 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.

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

a) It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.

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.

a) The moveForward method of the Auto class will be executed.

9) Consider the following code snippet: Vehicle aVehicle = new Auto(4,"gasoline"); String s = aVehicle.toString(); Assume that the Auto class inherits from the Vehicle class, and neither class has an implementation of the toString() method. Which of the following statements is correct? a) The toString() method of the Object class will be used when this code is executed. b) The toString() method of the String class will be used when this code is executed. c) This code will not compile because there is no toString() method in the Vehicle class. d) This code will not compile because there is no toString() method in the Auto class.

a) The toString() method of the Object class will be used when this code is executed.

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

a) This method will call itself

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.

a) myAuto.displayInfo()

9) When declared as protected, data in an object can be accessed by ______? a) Only by the class's methods and by all these subclasses. b) Only by that class methods, but all its subclasses, and by methods in classes within the same package. c) Only by the class's methods d) By any class

b) Only by that class's methods, by all of its subclasses, and by methods in classes within the same package.

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

b) Superclass

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? a) The Motorcycle class overrides the setVehicleClass method. b) The Vehicle class overrides the setVehicleClass method. c) The Motorcycle class overloads the setVehicleClass method. d) The Vehicle class overloads the setVehicleClass method

b) The Vehicle class overrides the setVehicleClass method

Which of the following statements about comparing objects is correct? a) The equals method is used to compare whether two references are to the same object. b) The equals method is used to compare whether two objects have the same contents. c) The == operator is used to compare whether two objects have the same contents. d) The equals method and the == operator perform the same actions.

b) The equals method is used to compare whether two objects have the same contents

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.

b) You can always use a subclass object in place of a superclass object

You are creating a Motorcycle class which is supposed to use an interface named Measurable. Which of the following class declaration statements will accomplish this? a) public class Motorcycle inherits Measurable b) public class Motorcycle implements Measurable c) public class Motorcycle interfaces Measurable d) public class Motorcycle extends Measurable

b) public class Motorcycle implements Measurable

If a subclass defines the same method name and the same parameter types for a method that appears in its superclass, ____. a) the subclass has overloaded its superclass's method. b) the subclass has overridden its superclass's method. c) the subclass has implemented its superclass's method. d) a compiler error will occur.

b) the subclass has overridden its superclass's method.

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

c) The subclass is overriding a superclass method.

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.

c) The subclass must use a public method of the superclass (if it exists) to update the superclass's private instance variable.

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.

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.

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.

d) dynamic lookup.

To create a subclass, use the ____ keyword. a) inherits b) implements c) interface d) extends

d) extends

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);

d) vesselLength(26.0);


Kaugnay na mga set ng pag-aaral

EMGT 5110 FLW Managerial Decision Making Dr. David Spurlock Fall 2017 (JUL-AUG)

View Set

COP 3014 Programming I Final Ch 1-8

View Set

Chapter 5 Integumentary System (Check Points & Review Questions )

View Set

CET215- Lesson 19 Security technologies (Quiz)

View Set

Ch. 20 Obsessive Compulsive and Related Disorders

View Set

Stats Week 2 - Data Displays, Descriptive Statistics, and Graphs

View Set

Passive Voice - English File int plus - File 8B

View Set