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?
Blog
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?
Select an appropriate expression to complete the following m…
Select an appropriate expression to complete the following method, which is designed to visit the elements in theList and replace each occurrence of the string “hello” with the string “goodbye”. public static void helloGoodbye(LinkedList theList) { ListIterator iterator = theList.listIterator(); while (iterator.hasNext()) { if (iterator.next().equals(“hello”)) { _____________________________ } } }
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?
Given the following class definition, which of the following…
Given the following class definition, which of the following are considered part of the class’s public interface? public class CashRegister { public static final double DIME_VALUE = 0.1; private static int objectCounter; public void updateDimes(int dimes) {. . .} private boolean updateCounter(int counter) {. . .} }
Consider the following code snippet: public class Motorcycle…
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?
Consider the following class hierarchy: public class Vehicle…
Consider the following class hierarchy: public class Vehicle { private String type; public Vehicle(String type) { this.type = type; } public String displayInfo() { return type; } } public class LandVehicle extends Vehicle { public LandVehicle(String type) { super(type); } } public class Auto extends LandVehicle { public Auto(String type) { _________; } } Complete the code in the Auto class constructor to store the type data.