Question: Question 11 Using the given definition of the Measurable interface: public interface Measurable { double getMeasure(); } Consider the following code snippet, assuming that BankAccount

Question 11

Using the given definition of the Measurable interface:

public interface Measurable { double getMeasure(); }

Consider the following code snippet, assuming that BankAccount has a getBalance method and implements the Measurable interface by providing an implementation for the getMeasure method:

Measurable m = new Measurable(); System.out.println(m.getMeasure()); 

Which of the following statements is true?

The code compiles but generates an exception at run time because getMeasure does not return a String.
The code compiles but generates an exception at run time because m does not reference a BankAccountobject.
The code does not compile because interface types cannot be instantiated.
The code executes, displaying the measure of the Measurable object.

Question 12

Consider the following class:

public class Player implements Comparable { private String name; private int goalsScored; // other methods go here public int compareTo(Object otherObject) { __________________________________ return (goalsScored  otherPlayer.goalsScored); } }

What statement can be used to complete the compareTo() method?

Player otherPlayer = otherObject;
Object otherPlayer = (Player) otherObject;
Player otherPlayer = (Player) otherObject;
Object otherPlayer = otherObject;

Question 13

Consider the following class:

public class BowlingGame implements Comparable { private int score; // other methods go here public int compareTo(Object otherObject) { BowlingGame otherGame = (BowlingGame) otherObject; __________________________________; } }

What statement can be used to complete the compareTo() method?

score otherGame.score
return (score otherGame.score)
otherGame.score score
return (otherGame.score score)

Question 14

Consider the following class:

public class Temperature implements Comparable { private int value; // other methods go here public int compareTo(Object otherObject) { Temperature otherTemp = (Temperature) otherObject; __________________________________; } }

Which is the best statement to use to complete the compareTo() method?

return Integer.compare(otherTemp.value, value)
return (value otherTemp.value)
return Integer.compare(value, otherTemp.value)
return (otherTemp.value value)

Question 15

Consider the following class:

public class Stock implements Comparable { private String name; private double price; // other methods go here public int compareTo(Object otherObject) { Stock otherStock = (Stock) otherObject; __________________________________; } }

Which is the best statement to use to complete the compareTo() method?

return (otherStock.price price)
return Double.compare(price, otherStock.price)
return Double.compare(otherStock.price, price)
return Integer.compare(price, otherStock.price)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!