What mechanism is used by a class that is designed to collect and store a growing set of values?
Blog
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?
Which of the following classifications of method behavior pr…
Which of the following classifications of method behavior produces acceptable side effects?
Consider the method in the following code snippet: public v…
Consider the method in the following code snippet: public void getRewardPoints() { System.out.println(“Your Reward Points balance is now “ + pointBalance); } Which of the following statements would not be a valid criticism of the design of this method?
Given the following code snippet: public static int newCalc(…
Given the following code snippet: public static int newCalc(int n) { if (n < 0) { return -1; } else if (n < 10) { return n; } else { return (1 + newCalc(n / 10)); } } What value will be returned when this code is executed with a call to newCalc(15)?
The use of the static keyword in a method declaration implie…
The use of the static keyword in a method declaration implies which of the following?
Complete the code for the calcPower recursive method shown b…
Complete the code for the calcPower recursive method shown below, which is intended to raise the base number passed into the method to the exponent power passed into the method: public static int calcPower(int baseNum, int exponent) { int answer = 0; ________________________ { answer = 1; } else { answer = baseNum * calcPower (baseNum, exponent – 1); } return answer; }
Suppose an object is intended to store its current position…
Suppose an object is intended to store its current position in a 2D array using private instance variables: private int row; private int column; Which code represents a method that would move the current position of the object one column to the right on the grid?
In Java, which of the following mechanisms describe the copy…
In Java, which of the following mechanisms describe the copying of an object reference into a parameter variable?