What is the best strategy for avoiding off-by-one errors?
Author: Anonymous
Which of the following code snippets displays the output exa…
Which of the following code snippets displays the output exactly 10 times?
Consider the following code snippet that appears in a subcla…
Consider the following code snippet that appears in a subclass: public void deposit(double amount) { transactionCount ++; deposit(amount); } Which of the following statements is true?
Complete the code for the myFactorial recursive method shown…
Complete the code for the myFactorial recursive method shown below, which is intended to compute the factorial of the value passed to the method: public int myFactorial(int anInteger) { if (anInteger == 1) { ______________________ } else { return (anInteger * myFactorial(anInteger – 1)); } }
Assuming that interface Resizable is declared elsewhere, con…
Assuming that interface Resizable is declared elsewhere, consider the following class declaration: public class InnerClassExample { public static void main(String[] args) { class SizeModifier implements Resizable { // class methods } __________________________ // missing statement } } Which of the following declarations can be used to complete the main method?
Consider the following code snippet: public class Vehicle {…
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?
What is the name of a class that has only accessor methods a…
What is the name of a class that has only accessor methods and no mutators methods?
What mechanism is used by a class that is designed to collec…
What mechanism is used by a class that is designed to collect and store a growing set of values?
Consider the following class: public class BowlingGame impl…
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?
Given the following class code: public class RecurseSample {…
Given the following class code: public class RecurseSample { public static void main(String[] args) { System.out.println(recurse(3)); } public static int recurse(int n) { int total = 0; if (n == 0) { return 0; } else { total = 3 + recurse(n – 1); } return total; } } What values will be printed when this code is executed?