Inheritance - Chapter 9

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following indicates that a class named ClassA class is a superclass of the ClassB class?

public class ClassB extends ClassA

Which reserved word must be used to call a method of a superclass from within a method of the subclass with the same method name?

super

To test whether an object belongs to a particular class type , use ___________________.

the instanceof operator

A class that represents the most general entity in an inheritance hierarchy is called a/an ________________________.

Superclass

Which of the following statements about comparing objects is correct?

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

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?

Vehicle should be the superclass, while Auto and Motorcycle should be the subclasses.

To create a subclass, use the _________ keyword.

extends

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 Motorcycle object inherits and can directly use the method setVehicleClass but cannot directly use the instance variable manufacturer.

Which of the following is true regarding subclasses?

A subclass may inherit methods and instance variables from its superclass, and may also implements its own methods and declare its own instance variables.

Consider the following class hierarchy: public class Vehicle { private String type; public Vehicle(String atype) { type = atype; } public String getType() { return type; } } public class LandVehicle extends Vehicle { public LandVehicle(String atype) { ... } } public class Auto extends LandVehicle { public Auto(String atype) { ... } } Which of the following code fragments in NOT valid in Java?

LandVehicle myAuto = new Vehicle("sedan");

To override a superclass method in a subclass, the subclass method ____________.

Must use the same method name and the same parameter types.

What must a subclass do to modify a private superclass instance variable?

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

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?

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

Consider the following code snippet that appears in a subclass: public void deposit(double amount) { transactionCount = transactionCount + 1; deposit(amout); } Which of the following statements is true?

This method will call itself.

Which of the following statements about inheritance is correct?

You can always use a subclass object in place of a superclass object.

Consider the following code snippet: public class Coin { private String name; . . . public boolean equals(Object otherCoin) { return name.equals(otherCoin.name): } } What is wrong with this code?

otherCoin must be cast as a Coin object before using the name.equals(otherCoin.name) statement.

If a subclass contains a method with the same name as a method in its superclass, but with different parameter types, the subclass is said to _______________ the method of the superclass.

overload

To ensure that an instance variable can only be accessed by the class that declared it, the variable should be declared as ________________.

private


Ensembles d'études connexes

English 11B - Unit 6: Final Exam

View Set

Meninges of the Brain, Frontal Section

View Set

ASREB - A4 - Liens & Encumbrances

View Set

FBLA Sports management and Marketing

View Set

chapter 4 the external environment

View Set