APCS Multiple Choice Exam

Ace your homework & exams now with Quizwiz!

Which of the following statements about a class that contains an abstract method is (are) true? I. You can't have any constructors in this class. II. This class must be declared as abstract. III. You can't declare any fields in this class.

Answer b: II only A class with an abstract method must also be declared abstract. You can have constructors and fields in an abstract class.

P and Q are booleans. Which of the following will always evaluate to true?

!(P && Q) || (P || Q) No combination of P and Q can make it evaluate false. If !(P && Q) evaluates to false, (P || Q) will evaluate to true and vice versa. !(T && T) || (T || T) = !(T) || (T) = F || T = T !(T && F) || (T || F) = !(F) || (T) = T || T = T !(F && F) || (F || F) = !(F) || (F) = T || F = T !(F && T) || (F || T) = !(F) || (T) = T || T = T

Susan is 5 years older than Matt. Three years from now Susan's age will be twice Matt's age. for (int s = 1; s <= 100; s++) { for (int m = 1; m <= 100; m++) { if (condition) System.out.println("Susan is " + s + " and Matt is " + m); } } What should be in place of condition to solve this problem?

Answer a: s == m + 5 && s + 3 == 2 * m + 6 Susan is 5 years older than Matt so s == m + 5 should be true and in 3 years she will be twice as old so s + 3 = 2 * (m + 3) = 2 * m + 6.

Consider the following field and method. private int[] numArray; public int getRunSize() { if (numArray.length == 0) return 0; int size = 1; while ((size < numArray.length) && (numArray[size - 1] > numArray[size])) { size++; } // assertion return size; } Which of the following assertions is true when execution reaches the line // assertion in getRunSize?

Answer a: (size == numArray.length) || (numArray[size - 1] <= numArray[size]) The while loop continues as long as the value of size is less than the number of elements in numArray and the value in numArray at an index of one less than size is greater than the value at numArray with an index of size. So if the loop stopped either the value in size equals the number of elements in the numArray or the value at the index size - 1 in numArray is less than or equal to the value at index size in numArray.

Consider the following declaration for a class that will be used to represent points in the xy-coordinate plane: public class Point { private int myX; // coordinates private int myY; public Point( ) { myX = 0; myY = 0; } public Point(int a, int b) { myX = a; myY = b; } // ... other methods not shown } The following incomplete class declaration is intended to extend the above class so that two-dimensional points can be named. public class NamedPoint extends Point { private String myName; // constructors go here // ... other methods not shown }

Answer a: I and III NamedPoint will inherit from Point all fields but the fields are private and they can not be directly accessed in NamedPoint. You can use super as the first line in a constructor to initialize inherited fields. You can also set your own fields in a constructor. If you don't use super as the first line in a constructor one will be put there by the compiler that will call the parent's no argument constructor.

In the GridWorld Case Study if you want to create a HungryCritter class that is a subclass of Critter and a HungryCritter object eats everything that is not a Rock or Critter within 2 cells of its current location, what method or methods should you override? I. getActors II. processActors III. act IV. makeMove

Answer a: I only The getActors method is what returns the objects within 1 cell of the current Critter. If you want to return all objects within 2 cells you will need to override this method. You don't need to override any additional methods unless you also want to override selectMoveLocation to allow the HungryCritter to move 2 cells away from its current location.

public boolean checkID (int id, String name, Student nextStudent) { if ((nextStudent.getName()).equals(name) && id == nextStudent.getID()) return true; else { id = nextStudent.getID(); nextStudent.setID(0); nextStudent.setName("VACANT"); return false; } }

Answer a: If you modify a primitive type parameter in Java in a method it will not change the value of the variable in the calling method. Java uses pass by value for parameters. So when you pass a variable to a method it will make a new variable that is only known in that method and assign its value to a copy of the original value. So if you pass in a variable j that has the value 4 a new variable id is created and its value is set to 4. Any changes to id will not affect the value of j If you pass an object reference to a method then a copy of the reference is made. So any changes you make to the object will persist.

Variable b is an array of ints. boolean flag = false; for (int i = 0; i < b.length; i++) { flag = flag && (b[i] > 0); } What best describes what this code segment does?

Answer a: Sets flag to false Correct, because flag is initialized to false, the && operation will always computer to false as well.

Assume that x is an initialized int variable. The code segment: if (x > 2) x *= 2; if (x > 4) x = 0; is equivalent to which of the following code segments?

Answer a: if (x > 2) x = 0; If x > 2, say 3, the first if will reset x so it will be then also be greater than 4. Thus, whenever x is greater than 2, both if will be true, and x will be set to 0.

Consider the following code segment for(int i = 0; i < 5; i++) { for(int j=0; j < 5; j++) System.out.println("*"); } How many stars are output when this code is executed?

Answer b: 25 This is correct, because the first loop will execute 5 times, and for each time through, the second loop will execute 5 times. So the answer is the number of times through the first loop times the number of times through the second.

Consider the following two classes. public class Base { public void methodOne() { System.out.print("A"); methodTwo(); } public void methodTwo() { System.out.print("B"); } } public class Derived extends Base { public void methodOne() { super.methodOne(); System.out.print("C"); } public void methodTwo() { super.methodTwo(); System.out.print("D"); } } Assume that the following declaration appears in a client program. Base b = new Derived(); What is the result of the call b.methodOne()?

Answer b: ABDC Even though b is declared as type Base it is created as an object of the Derived class, so all methods to it will be resolved starting with the Derived class. So the methodOne() in Derived will be called. This method first calls super.methodOne so this will invoke the method in the superclass (which is Base). So next the methodOne in Base will execute. This prints the letter "A" and invokes this.methodTwo(). Since b is really a Derived object, we check there first to see if it has a methodTwo. It does, so execution continues in Derived's methodTwo. This method invokes super.methodTwo. So this will invoke the method in the super class (Base) named methodTwo. This method prints the letter "B" and then returns. Next the execution returns from the call to the super.methodTwo and prints the letter "D". We return to the Base class methodOne and return from that to the Derived class methodOne and print the letter "C". Derived methodOne Base methodOne print "A" Derived methodTwo Base methodTwo print "B" return to derived methodTwo print "D" return to derived methodOne print "C"

Which of the following statements about interfaces is (are) true? I. One interface can inherit from another. II. You can declare a abstract method in an interface. III. You can create a new object using an interface. If I have an interface named List I can do List aList = new List();

Answer b: I and II only I and II are both true. III is false. You can't use the new operator with an interface name. You can declare variables to be of an interface type. You could say List aList = new ArrayList();

Which of the following is (are) the best way(s) to add a new Bug to the Grid in the GridWorld Case Study? I. using the put method in Grid II. using the putSelfInGrid method in Actor III. using a new method in Bug that calls the put method in Grid

Answer b: II only The putSelfInGrid method checks that the actor isn't already in a grid before it calls the put method of Grid to add the actor to the grid. It also sets the actor's location to be the location in the grid.

If you have the following: String s1 = new String("Hi There"); String s2 = new String("Hi There"); String s3 = s1; Which of the following would return true? I. (s1 == s2) II. (s1.equals(s2)) III. (s1 == s3) IV. (s2.equals(s3))

Answer b: II, III and IV String overrides equals to check if the two string objects have the same characters. The == operator checks if two object references refer to the same object. So II is correct since s1 and s2 have the same characters. Number III is correct since s3 and s1 are referencing the same string so they will be ==. And s2 and s3 both refer to strings that have the same characters so equals will be true in IV. The only one that will not be true is I since s1 and s2 are two different objects (even though they have the same characters).

We want to define a new class SlowCritter that extends Critter. An object of this new class should move like a Critter except that it will only have a 50% chance of moving if it can move. Which of the following methods should this class override? I. act II. getActors III. makeMove IV. getMoveLocations

Answer b: III only. The makeMove method is where the move takes place as long as the passed location isn't null. This should be changed to move only if the result of Math.random() is less than 0.5. public void makeMove(Location loc) { if (loc == null) removeSelfFromGrid(); else if (Math.random() < 0.5) moveTo(loc); }

Which will cause the longest execution of a sequential search looking for a value in an array of 10 integers?

Answer b: The value isn't in the array A sequential search loops through the elements of an array starting with the first and ending with the last and returns from the loop as soon as it finds the passed value. It has to check every value in the array when the value it is looking for is not in the array. This would take 10 executions of the loop.

Consider the following code segment for(int i = 0; i < 5; i++) { for(int j=0; j < 5; j++) System.out.println("*"); } How many stars are output when this code is executed?

Answer c: 25 This is correct, because the first loop will execute 5 times, and for each time through, the second loop will execute 5 times. So the answer is the number of times through the first loop times the number of times through the second.

Given the following declaration of a field in a class: public static final String GREETING = "Hi"; Which of these statements is not true?

Answer c: Each object of this class has a copy of GREETING Static variables are not created for each object. They are created in the object that represents the class (an object of the class named Class). All objects of a class keep a reference to their Class object and can access fields in it. You can get the class object from an object using the method getClass().

Consider the following method: public boolean checkID (int id, String name, Student nextStudent) { if ((nextStudent.getName()).equals(name) && id == nextStudent.getID()) return true; else { id = nextStudent.getID(); nextStudent.setID(0); nextStudent.setName("VACANT"); return false; } } Assume a class Student is defined with private instance fields name and ID. The class also has public accessors and mutators for these two fields. The method intends to check that the name and ID fields of the passed nextStudent match the passed name and id. If the names and/or the IDs do not match then it sets id to the value of nextStudent.getID(), resets the fields ID and name, and returns false. The intention is for the calling program to check for false on the return and then get the incorrect id stored in the variable that was passed as the parameter id, but this doesn't work. Which answer best describes why this doesn't work?

Answer c: If you modify a primitive type parameter in Java in a method it will not change the value of the variable in the calling method. Java uses pass by value for parameters. So when you pass a variable to a method it will make a new variable that is only known in that method and assign its value to a copy of the original value. So if you pass in a variable j that has the value 4 a new variable id is created and its value is set to 4. Any changes to id will not affect the value of j If you pass an object reference to a method then a copy of the reference is made. So any changes you make to the object will persist.

public int max(int a, int b, int c) { if ((a > b) && (a > c)) return a; if ((b > a) && (b > c)) return b; if ((c > a) && (c > b)) return c; } Which of the following best describes why this method does not compile?

Answer c: It is possible to reach the end of the method without returning a value. If a is greater than b and c the first return will execute. If b is greater than a and c the second return will execute. If c is greater than a and b the third return will execute. But if any of a, b, or c are equal to each other none of these conditions will be true and the end of the method will be reached without a return statement having executed. The compiler will not allow this.

The following classes are defined: public class Car { private int fuel; public Car() { fuel = 0; } public Car(int g) { fuel = g; } public void addFuel() { fuel++; } public void display() { System.out.print(fuel + " "); } } public class RaceCar extends Car { public RaceCar(int g) { super(2*g); } } What is the result when the following code is compiled and run? Car car = new Car(5); Car fastCar = new RaceCar(5); car.display() car.addFuel(); car.display(); fastCar.display(); fastCar.addFuel(); fastCar.display();

Answer c: The code compiles and runs with no errors, the output is: 5 6 10 11 The code compiles correctly, and because RaceCar extends the Car class, all the public methods of Car can be used by RaceCar objects. Also, a variable Car can refer to a Car object or an object of any subclass of Car. An object always knows the class that created it, so even though fastCar is declared to be a Car the constructor that is executed is the one for RaceCar.

Under which of these conditions will a sequential search be faster than a binary search?

Answer c: The search value is the first element in the array. Correct, Only when the search value is the first item in the array, and thus the first value encountered in sequential search, will sequential be faster than binary.

Which will cause the shortest execution of a binary search looking for a value in an array of integers sorted in ascending order? The array has an odd number of integers.

Answer c: The value is in the middle of the array A binary search starts at the middle of a sorted array so if that is the value you are searching for execution can stop then.

Consider the following data field and method: private ArrayList<Integer> nums; // precondition: nums.size() > 0; // nums contains Integer objects public void numQuest() { int k = 0; Integer zero = new Integer(0); while (k < nums.size()) { if (nums.get(k).equals(zero)) nums.remove(k); k++; } } Assume that ArrayList nums initially contains the following Integer values. [0, 0, 4, 2, 5, 0, 3, 0] What will ArrayList nums contain as a result of executing numQuest ?

Answer c: [0, 4, 2, 5, 3] This code will loop through the array list and if the current value at the current index (k) is 0 it will remove it. When you remove a value from an array list it moves all values to the right of that down one. So the first 0 will be deleted but the second one will not since k is incremented even if you remove something. You should only increment k if you didn't remove something and then you would remove all 0's from the list.

Given the following incomplete class declaration: public class TimeRecord { private int hours; private int minutes; // 0<=minutes<60 public TimeRecord(int h, int m) { hours = h; minutes = m; } // postcondition: returns the // number of hours public int getHours() { /* implementation not shown */ } // postcondition: returns the number // of minutes; 0 <= minutes < 60 public int getMinutes() { /* implementation not shown */ } // precondition: h >= 0; m >= 0 // postcondition: adds h hours and // m minutes to this TimeRecord public void advance(int h, int m) { hours = hours + h; minutes = minutes + m; /* missing code */ } // ... other methods not shown } Which of the following can be used to replace the missing code in the advance method so that it will correctly update the time?

Answer c: hours = hours + minutes / 60; minutes = minutes % 60; This will update hours and minutes correctly. It will add the floor of the division of minutes by 60 to hours and then set minutes to the remainder of the division of minutes by 60

After the execution of this program, what is the output? for (int j = 1; j < 5; j++) { for (int k = 1; k <= 5; k++) System.out.print(j * k + " "); System.out.println(); }

Answer d: 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 The variable j loops from 1 to 4 and k loops from 1 to 5 (k <= 5) and each time in the inner loop it prints j * k and after the inner loop it will print a new line. for j=1; 1*1 1*2 1*3 1*4 1*5 for j=2; 2*1 2*2 2*3 2*4 2*5 for j=3; 3*1 3*2 3*3 3*4 3*5 for j=4; 4*1 4*2 4*3 4*4 4*5

Consider the following method: public int m1(int[] a) { a[1]--; return (a[1] * 2); } If int[] a = {8, 3, 1}, what is the value in a[1] after m1(a); is run?

Answer d: 2 The statement a[1]--; is the same as a[1] = a[1] - 1; so this will change the 3 to a 2. The return (a[1] * 2) does not change the value at a[1].

There is a method called checkString that determines whether a string is the same forwards and backwards. The following data sets can be used for testing the method. What advantage does Data Set 2 have over Data Set 1? Data Set 1 Data Set 2 aba bcb abba bcd aBa

Answer d: Data Set 2 contains one string which should return true and one that should return false. Correct, all of the strings in Data Set 1 should return true, so the false condition is never tested.

At a certain high school students receive letter grades based on the following scale. Numeric Score Letter Grade 93 or Above A From 84 to 92 inclusive B From 75 to 83 inclusive C Below 75 F Which of the following code segments will assign the correct string to grade for a given integer score?

Answer d: I and III only Both I and III are syntatically correct. Choice I uses && in the condition. Additionally, both choices make sure the numbers are inclusive by using <= and >=.

Consider the following class definitions. public class Book { public String getISBN() { // implementation not shown } // constructors, fields, and other methods not shown } public class Dictionary extends Book { public String getDefinition(String word) { // implementation not shown } // constructors, fields, and methods not shown } Assume that the following declaration appears in a client class. Book b = new Dictionary(); Which of the following statements would compile without error? I. b.getISBN(); II. b.getDefinition("wonderful"); III. ((Dictionary) b).getDefinition("wonderful");

Answer d: I and III only I is correct because variable b has been declared to be an object of the class Book so you can invoke any public methods that are defined in the book class or in parents of Book. II is not correct because you can't invoke methods in the Dictionary class directly on b since b is declared to be of type Book not type Dictionary and Dictionary is a subclass of Book not a parent class of Book. III is correct because you can cast b to type Dictionary and then invoke public methods in Dictionary.

Given an array, which of the following condition must be true in order to search for a value using binary search? I. The values in the array must be integers. II. The values in the array must be in sorted order. III. The array must not contain duplicate values.

Answer d: II only Correct, the only condition for using a Binary Search is that the values must be ordered.

Consider the following partial class declaration. public class Person implements Comparable { private String firstName; private String lastName; public int compareTo(Object test) { // implementation not shown } // constructors, other fields, and methods not shown } Assume that the Person objects are ordered by last name and then first name. Which of the following will correctly implement compareTo for the Person class?

Answer d: III only Number I will give strange results since you add the result of the compare of the first and last names. It can give a result of 0 when a compare of the first name returns a positive number of value x and a compare of the last name returns a negative number of value x. Number II would be correct if we were ordering on first name and then last name. Number III is correct. It compares the last names and if they don't match returns the result of that comparison and if they do match returns the result of comparing the first names.

public class Person implements Comparable { code for class including a compareTo() method } public class Player extends Person { code for class } Which declaration will result in a compiler error?

Answer d: Player p = new Person(); A variable can hold the declared type and any child of that type. The class Person is not a child of the class Player so this is not allowed and will not compile.

Which one of the following statements about method overloading and overriding is true?

Answer e: Overriding allows for polymorphism which means that the actual method that gets called at runtime depends on the type of the object at runtime. Overriding allows a child class to define a method with the same name and method signature as a parent class. The child method will be called instead of the parent method. This allows inheritance-based polymorphism since the method called at runtime will depend on the type of the object.

public class Student { public String getFood() { return "Pizza"; } public String getInfo() { return this.getFood(); } } public class GradStudent extends Student { public String getFood() { return "Taco"; } } What is the output from this: Student s1 = new GradStudent(); s1.getInfo();

Answer d: Taco Objects know what class they are created as and all methods are resolved starting with that class. If the method isn't found in that Class the parent class is checked (and so on until it is found). So it will first look for getInfo in GradStudent and when it doesn't find it it will look in Student. In getInfo it calls this.getFood. Again, it will first look for this method in Student. Student does have a getFood method so it will execute this one.

Consider the following code segment: ArrayList<Integer> list = new ArrayList<Integer>(); list.add(new Integer(1)); list.add(new Integer(2)); list.add(new Integer(3)); list.set(2, new Integer(4)); list.add(2, new Integer(5)); list.add(new Integer(6)); System.out.println(list); What is printed as a result of executing the code segment?

Answer d: [1, 2, 5, 4, 6] The add method that takes just a value as a parameter adds that value to the end of the list. The set replaces the value at that index with the new value. The add with parameters of an index and a value puts the passed value at that index and moves any existing values by one index to the right (increments the index). So the list looks like: 1 // add 1 1 2 // add 2 1 2 3 // add 3 1 2 4 // set index 2 to 4 1 2 5 4 // add 5 to index 2 (move rest right) 1 2 5 4 6 // add 6 to end

Given the following method: public boolean check(String s) { return s.length() >= 2 && (s.charAt(0) == s.charAt(1) || check(s.substring(1))); } This method will return true if and only if:

Answer d: s contains two or more of the same character in a row This will return true when s has at least 2 characters in it and at least 2 characters are the same in a row.

Question 15 Consider the following method: private int product(int n) { if(n <= 1) return 1; else return n * product(n - 2); } What is the result of product(5)

Answer e: 15 The recursion works as follows: product(5) -> 5 * product(3) -> 3 * product(1) -> 1 Thus, 1 * 3 = 3, 3 * 5 = 15

Consider the following recursive method. public static int mystery(int n) { if (n == 0) return 1; else return 3 * mystery (n - 1); } What value is returned as the result of the call mystery(5)?

Answer e: 243 For the call mystery(5), n != 0 so the else statement is executed. This results in the next recursive call of mystery with the value (4). This will continue until the call mystery(0) is executed. At this point, the value 1 will be returned. Then each call of mystery can return with the 3 * the result of the recursive call. So this method will compute 3 to the given power. mystery(5) 3 * (mystery(4)) mystery(4) 3 * (mystery(3)) mystery(3) 3 * (mystery(2)) mystery(2) 3 * (mystery(1)) mystery(1) 3 * (mystery(0)) mystery(0) = 1 return 3 * 1 = 3 return 3 * 3 = 9 return 3 * 9 = 27 return 3 * 27 = 81 return 3 * 81 = 243

Which of the following is a reason to use an ArrayList instead of an array?

Answer e: An ArrayList resizes itself as necessary as items are added, but an array does not. Yes, an ArrayList is really a dynamic array (one that can grow or shrink as needed). When an ArrayList is full and you try to add another item a new larger array is created and all items are copied from the original array. The new array is typically 2 times as large as the original.

Consider the following: String s1 = "Hi There"; String s2 = s1; String s3 = s2; String s4 = s1; s2 = s2.toLowerCase(); s3 = s3.toUpperCase(); s4 = null; What string is referrenced by s1?

Answer e: Hi There Strings are immutable meaning that any changes to a string creates and returns a new string, so the string referred to by s1 does not change

Consider the following code segment String s1 = "xyz"; String s2 = s1; String s3 = s2; After this code is executed, which of the following statements will evaluate to TRUE? I. s1.equals(s3) II. s1 == s2 III. s1 == s3

Answer e: I,II, and III This is correct, as the "equals" operation is overloaded for use with strings, so I is true. II and III are both true because the code as written assigns both s2 and s3 to the same object as s1.

Consider the following class declaration. public class ParkingPass { private int numLeft; // constructor not shown public int getNumLeft() { return numLeft; } public String toString() { return "Parking pass has " + numLeft + " left"; } } If the following declaration appears in a client class. ParkingPass pass = new ParkingPass(); Which of these statements can be used in the client class? I. System.out.println(pass.numLeft); II. System.out.println(pass); III. System.out.println(pass.getNumLeft());

Answer e: II and III I is wrong because you can not use dot access to a private field in a client class. II is correct because it will call the toString method in ParkingPass. The toString method is also inherited from Object but since ParkingPass provides one the one in ParkingPass will be called instead of the one in Object. III is correct because getNumLeft is a public method.

Consider the following class definitions. public class Item { private int x; public void setX(int theX) { x = theX; } // ... other methods not shown } public class EnhancedItem extends Item { private int y; public void setY(int theY) { y = theY; } // ... other methods not shown } Assume that the following declaration appears in a client program. EnhancedItem enItemObj = new EnhancedItem(); Which of the following statements would be valid? I. enItemObj.y = 32; II. enItemObj.setY(32); III. enItemObj.setX(52);

Answer e: II and III only I is wrong because y is a private field and thus can not be directly accessed. II is correct because EnhancedItem has setY as a public method. III is correct because EnhancedItem inherits the public method setX from Item.

The following method attempts to perform an insertion sort: public void sort() 0: { 1: for (int i = 1; i < a.length; i++) 2: { 3: int next = a[i]; 4: // Move all larger elements to the right 5: int j = i; 6: while (j > 0 && a[j - 1] > next) 7: { 8: a[j-1] = a[j]; 9: j--; 10: } 11: // Insert the element 12: a[j] = next; 13: } 14: }

Answer e: In line 8 it should be a[j] = a[j-1]; Larger elements of the array should be shifted to the right (toward the back) of the array. The statement a[j-1] = a[j] shifts the element to the front, which is the opposite of what needs to be done.

Under which of these conditions is it appropriate to overload a method (ie: the class will contain two methods with the same name)

Answer e: The methods have different numbers of parameters Correct, overloading is necessary is when two functions that perform the same essential operation take a different number of parameters.

Consider the following code segment. The code is intended to read nonnegative numbers and compute their sum until a negative number is read. However, it does not work as intended. (Assume that readInt works correctly to read the next number from the input stream.) int i = 1; int sum = 0; while (i >= 0) { System.out.println("enter a number (enter 0 to quit): "); i = readInt(); // read int from user sum = sum + i; } System.out.println("sum: " + sum); Which of the following best describes the error in the program?

Answer e: The negative number that signals the end of the input is included in the sum. The value of i is always added to the sum before the check if i is a nonnegative number.

What is the output from the following code? String s = "Georgia Tech"; String s1 = s.substring(0,7); String s2 = s1.substring(2); String s3 = s2.substring(0,3); System.out.println(s3);

Answer e: org The method substring(a,b) means start at a and stop before b. The method substring(a) means start at a and go to the end of the string. The first character in a string is at index 0. Georgia Tech // String s = "Georgia Tech"; Georgia // String s1 = s.substring(0,7); orgia // String s2 = s1.substring(2); org // String s3 = s2.substring(0,3);

Given the following method: public boolean check(String s) { return s.length() >= 2 && (s.charAt(0) == s.charAt(1) || check(s.substring(1))); } This method will return true if and only if:

Answer e: s contains two or more of the same character in a row This will return true when s has at least 2 characters in it and at least 2 characters are the same in a row.

What is the best explanation for what is meant by overriding a method?

Defining a method with the same name and parameter list as an inherited method To override a method you create a method with the same name and parameter list as a method you have inherited from a superclass.

Assume that variable b is an array of k integers and that the following is true: b[0] != b[k] for all k such that 1 <= k Which of the following statements is a valid conclusion?

The value in b[0] does not occur anywhere else in the array Correct, the assertion denotes that b[0] occurs only once, regardless of the order or value of the other array values.

Which of the following statements assigns the letter S to the third row and first column of a two-dimensional array named letterGrid (assuming row-major order).

letterGrid[2][0] = "S"; In Java two dimensional arrays are really arrays of arrays and can be row-major or column-major. In row-major order the row is specified first followed by the column. Row and column indicies start with 0. So letterGrid[2][0] is the 3rd row and 1st column.


Related study sets

Microeconomics - Perfect Competition

View Set

M4: zyBook Activities Multiple Choice

View Set

1) Cell structure and Organisation

View Set

Success Pharmacology - Comprehensive Examination

View Set

Lesson 9 Sentences 2 颜色 衣服 上衣 裤子 鞋子

View Set