Exam 9: Inheritance

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which of the following is true regarding subclasses?

Free
(Multiple Choice)
4.8/5
(37)
Correct Answer:
Verified

C

Which of the following indicates that a class named Class1 is a subclass of a class named Class2?

Free
(Multiple Choice)
4.9/5
(46)
Correct Answer:
Verified

A

Consider the following code snippet: public class Motorcycle extends Vehicle { ) . . Public Motorcycle(int numberAxles) { Super(numberAxles); } } What does this code do?

Free
(Multiple Choice)
4.9/5
(41)
Correct Answer:
Verified

A

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.

(Multiple Choice)
5.0/5
(33)

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?

(Multiple Choice)
5.0/5
(36)

Which of the following indicates that the Motorcycle class is a subclass of the Vehicle class?

(Multiple Choice)
4.8/5
(40)

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?

(Multiple Choice)
4.8/5
(50)

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

(Multiple Choice)
5.0/5
(39)

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?

(Multiple Choice)
4.9/5
(39)

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?

(Multiple Choice)
4.8/5
(36)

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?

(Multiple Choice)
4.8/5
(29)

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?

(Multiple Choice)
4.7/5
(33)

All rodents are mammals and all canines are mammals. No canines are rodents and no rodents are canines. What hierarchy best captures this information?

(Multiple Choice)
4.8/5
(34)

Consider the following code snippet: Employee programmer = new Employee(10254, "exempt"); String s = programmer.toString(); Assume that the Employee class has not implemented its own toString() method. What value will s contain when this code is executed?

(Multiple Choice)
4.9/5
(33)

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.

(Multiple Choice)
4.8/5
(33)

Consider the following code snippet: double salary = 45000.00; String sal = "Current salary is " + salary; Which of the following statements is correct?

(Multiple Choice)
4.9/5
(29)

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

(Multiple Choice)
4.8/5
(35)

The ____ reserved word in a class definition ensures that subclasses cannot be created from this class.

(Multiple Choice)
4.8/5
(32)

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?

(Multiple Choice)
4.9/5
(33)

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

(Multiple Choice)
4.8/5
(35)
Showing 1 - 20 of 101
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)