Exam 9: Inheritance

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

Which reserved word must be used to call a method of a superclass?

(Multiple Choice)
4.8/5
(37)

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

(Multiple Choice)
5.0/5
(41)

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

(Multiple Choice)
5.0/5
(31)

Which of the following is true regarding subclasses?

(Multiple Choice)
4.9/5
(38)

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?

(Multiple Choice)
4.9/5
(40)

Consider the following inheritance hierarchy diagram: Consider the following inheritance hierarchy diagram:   Which of the following statements is correct? Which of the following statements is correct?

(Multiple Choice)
4.7/5
(36)

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?

(Multiple Choice)
4.8/5
(37)

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 ____.

(Multiple Choice)
4.7/5
(33)

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?

(Multiple Choice)
4.9/5
(40)

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

(Multiple Choice)
4.9/5
(39)

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

(Multiple Choice)
4.8/5
(40)

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() { _______________; } }

(Multiple Choice)
4.7/5
(42)

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

(Multiple Choice)
4.7/5
(36)

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 ____.

(Multiple Choice)
4.8/5
(40)

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

(Multiple Choice)
4.9/5
(40)

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 ____.

(Multiple Choice)
4.9/5
(39)

A class from which you cannot create objects is called a/an ____.

(Multiple Choice)
4.7/5
(45)

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?

(Multiple Choice)
5.0/5
(32)

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

(Multiple Choice)
4.9/5
(39)

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

(Multiple Choice)
4.8/5
(35)
Showing 41 - 60 of 101
close modal

Filters

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