600.107 Intro Prog. in Java Practice Test3 1 ----------------------------- What is the output of the following program? Show the contents of memory for partial credit. class test3a { public static void main (String[] args) { char [] ra1 = {'c', 'd', 'e', 'f', 'c'}; char [] ra2 = {'a', 'b', 'c', 'b', 'a'}; if (tester(ra1, 0, ra1.length-1)) System.out.println(ra1); else System.out.println("ra1 fails test"); if (tester(ra2, 0, ra2.length-1)) System.out.println(ra2); else System.out.println("ra2 fails test"); } public static boolean tester (char [] ra, int start, int end) { if (start > end) return true; if (start == end) return true; if (ra[start] != ra[end]) return false; else return tester(ra, start+1, end-1); } } 2 ----------------------------- Write a static RECURSIVE method which has a single integer parameter and prints the integers from that number to 0 in descending order. If the method is called with a negative number, it should do nothing. If it's called with 0, it should print 0. If it's called with 5, it should print 5 4 3 2 1 0. 3 ----------------------------- Write a statement (as it might appear in main) to call the method above in order to output the integers from 10 to 0. 4a ----------------------------- Given the following array, what does it look like in memory after the first pass of the outer loop of a SELECTION SORT? (The inner loop will fully execute one time.) Circle one choice. r = {25, 40, 13, 7, 90} after 1st pass: 4b ------------------------------ Given the following array, what does it look like in memory after the first pass of the outer loop of a BUBBLE SORT. (The inner loop will fully execute one time.) r = {25, 40, 13, 7, 90} after 1st pass: 5a ---------------------------------- Given the following array, what numbers would be looked at (in what order) during a BINARY SEARCH for the number 15? r = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24} 5b ---------------------------------- Given the following array, what numbers would be looked at during a LINEAR SEARCH for the number 20? r = {23, 13, 29, 31, 20, 30, 12, 24, 90} 6 ----------------------------- Assuming you have a sorted array, which type of search is usually faster (ie, faster in the worst case), binary search or linear search? 7 ----------------------------- What is the base class (parent) of all classes in Java? 8a ----------------------------- Which 3 methods from the Object class should all your classes override? 8b ----------------------------- Which classes below have an inheritance relationship? Indicate which are the subclasses and which are the superclasses. student teacher student teaching assistant blue jay bird 9a ------------------------------ Which Java interface contains the compareTo method? 9b ----------------------------- True False 1) A class can implement multiple interfaces in Java. True False 2) A class can inherit from multiple classes in Java. True False 3) A class can be the base class of many classes in Java. True False 4) Inheritance is referred to as an "IS-A" type relationship. True False 5) If a class implements an interface, it can pick and choose which methods from the interface to provide a definition for. True False 6) Protected access enables subclasses to access members of their superclass. THERE WILL BE MORE QUESTIONS ON INHERITANCE, INTERFACES AND EXCEPTIONS STARTING SUMMER 2005, BUT I DON'T HAVE SAMPLE QUESTIONS FOR THESE TOPICS.