Exam 9: Inheritance

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

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?

(Multiple Choice)
4.7/5
(30)

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

(Multiple Choice)
4.8/5
(31)

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?

(Multiple Choice)
4.8/5
(47)

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

(Multiple Choice)
4.8/5
(38)

Consider the following code snippet: public class Vehicle { Protected int numberAxles; ) . . } Data in the numberAxles variable can be accessed by ____.

(Multiple Choice)
4.8/5
(37)

Which of the following is true regarding subclasses?

(Multiple Choice)
4.9/5
(38)

Which of the following statements about abstract methods is true?

(Multiple Choice)
4.7/5
(34)

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?

(Multiple Choice)
4.8/5
(43)

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?

(Multiple Choice)
4.8/5
(38)

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?

(Multiple Choice)
4.8/5
(34)

Which of the following statements about comparing objects is correct?

(Multiple Choice)
4.8/5
(37)

Consider the following code snippet of a function object public interface Measurer { Double measure(______ anObject); } Complete this code to allow the interface to handle all classes?

(Multiple Choice)
4.8/5
(36)

When declared as protected, data in an object can be accessed by ____.

(Multiple Choice)
4.9/5
(35)

All hamsters are rodents and all rodents are mammals. What hierarchy best captures this information?

(Multiple Choice)
4.9/5
(36)

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

(Multiple Choice)
4.9/5
(37)

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?

(Multiple Choice)
4.7/5
(42)

A class that represents a more specific entity in an inheritance hierarchy is called a/an ____.

(Multiple Choice)
4.8/5
(31)

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

(Multiple Choice)
4.7/5
(43)

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

(Multiple Choice)
4.9/5
(31)

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)

(Multiple Choice)
4.8/5
(30)
Showing 21 - 40 of 101
close modal

Filters

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