01. Consider the following code segment. int x = int n = 0; if (x < 500) { if (x > 750) n = 100; else n = 200; } else { if (x < 300) n = 300; else n =

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

AGVISE Laboratories %Zone or Grid Samples – Northwood laboratory
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Feichter_DPG-SYKL03_Bild-01. Feichter_DPG-SYKL03_Bild-02.
& dding ubtracting ractions.
1 Inheritance Classes and Subclasses Or Extending a Class.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 38.
Multiplication X 1 1 x 1 = 1 2 x 1 = 2 3 x 1 = 3 4 x 1 = 4 5 x 1 = 5 6 x 1 = 6 7 x 1 = 7 8 x 1 = 8 9 x 1 = 9 10 x 1 = x 1 = x 1 = 12 X 2 1.
Division ÷ 1 1 ÷ 1 = 1 2 ÷ 1 = 2 3 ÷ 1 = 3 4 ÷ 1 = 4 5 ÷ 1 = 5 6 ÷ 1 = 6 7 ÷ 1 = 7 8 ÷ 1 = 8 9 ÷ 1 = 9 10 ÷ 1 = ÷ 1 = ÷ 1 = 12 ÷ 2 2 ÷ 2 =
Chapter 1 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
1 1  1 =.
Jeopardy Q $100 Q $100 Q $100 Q $100 Q $100 Q $200 Q $200 Q $200
2 pt 3 pt 4 pt 5 pt 1 pt 2 pt 3 pt 4 pt 5 pt 1 pt 2 pt 3 pt 4 pt 5 pt 1 pt 2 pt 3 pt 4 pt 5 pt 1 pt 2 pt 3 pt 4 pt 5 pt 1 pt ShapesPatterns Counting Number.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
Year 6 mental test 15 second questions Numbers and number system Numbers and the number system, Measures and Shape.
Around the World AdditionSubtraction MultiplicationDivision AdditionSubtraction MultiplicationDivision.
I can interpret intervals on partially numbered scales and record readings accurately ? 15 ? 45 ? 25 ? 37 ? 53 ? 64 Each little mark.
Chapter 7: Arrays In this chapter, you will learn about
Break Time Remaining 10:00.
The basics for simulations
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Chapter 17 Linked Lists.
Linked List A linked list consists of a number of links, each of which has a reference to the next link. Adding and removing elements in the middle of.
Data Structures ADT List
ABC Technology Project
Look at This PowerPoint for help on you times tables
15. Oktober Oktober Oktober 2012.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
We are learning how to read the 24 hour clock
1..
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Sets Sets © 2005 Richard A. Medeiros next Patterns.
LO: Count up to 100 objects by grouping them and counting in 5s 10s and 2s. Mrs Criddle: Westfield Middle School.
1 Chapter 4 The while loop and boolean operators Samuel Marateck ©2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Before Between After.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
25 seconds left…...
Subtraction: Adding UP
Equal or Not. Equal or Not
Slippery Slope
Ratio Unit – Part I  a) c)  b)d) 3: words 60 words per minute 180:3.
: 3 00.
Number bonds to 10,
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Types of selection structures
Nodo Gastronómico en la Provincia de Elqui
We will resume in: 25 Minutes.
Fractions Simplify: 36/48 = 36/48 = ¾ 125/225 = 125/225 = 25/45 = 5/9
Clock will move after 1 minute
PSSA Preparation.
& dding ubtracting ractions.
Select a time to count down from the clock above
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
9-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Multiplication Facts Practice
Graeme Henchel Multiples Graeme Henchel
Schutzvermerk nach DIN 34 beachten 05/04/15 Seite 1 Training EPAM and CANopen Basic Solution: Password * * Level 1 Level 2 * Level 3 Password2 IP-Adr.
MC Question Strategies
Presentation transcript:

01. Consider the following code segment. int x = int n = 0; if (x < 500) { if (x > 750) n = 100; else n = 200; } else { if (x < 300) n = 300; else n = 200; } System.out.println(n); What is printed as a result of executing the code segment? (A)Unknown without the value of x (B)0 (C) 100 (D)200 (E)300

02. Consider the following code segment. int n = int count = 0; int p = 0; int q = 0; for (p = 1; p < n; p++) for (q = 1; q < n; q++) count++; System.out.println(count); What is the value of count when the code finishes executing? (A)n 2 (B)n (C) (n - 1) 2 (D)p * q (E)both C and D

03. Consider the following code segment. int count = 10; for (int p = 0; p < 15; p+=3) if (p % 2 == 0) count++; else count--; System.out.println(count); What is printed as a result of executing the code segment? (A)10 (B)11 (C) 12 (D)13 (E)14

04. Consider the following program. public class Method04 { public static void main (String args[]) { int p = 10; int q = 20; swap(p,q); System.out.println(p + " " + q); } public static void swap(int x, int y) { int temp = x; x = y; y = temp; } What is printed as a result of executing the program? (A)10 20 (B)20 10 (C) (D)20 20 (E)0 0

05. Consider the following program. public class Method05 { public static void main (String args[]) { int[] list = {1,2,3,4,5,6,7,8,9}; swap(list,3,4); System.out.println(list[3] + " " + list[4]); } public static void swap(int[] x, int p, int q) { int temp = x[p]; x[p] = x[q]; x[q] = temp; } What is printed as a result of executing the program? (A)3 4 (B)4 3 (C) 4 5 (C)5 4 (D)Exception error

06. public class Method06 { public static void main (String args[]) { System.out.println(tango(120,108)); } public static int tango(int n1, int n2) { int temp = 1; int rem = 1; while (rem != 0) { rem = n1 % n2; if (rem == 0) temp = n2; else { n1 = n2; n2 = rem; } return temp; } What is printed as a result of executing the program? (A)120 (B)108 (C) 12 (D)9 (E)1

07. Consider the following Aardvark class and code segment. Aardvark a = new Aardvark(100); System.out.println(a.getAardvarks()); class Aardvark { private int numAardvarks; public void Aardvark(int aardvarks) { numAardvarks = aardvarks; } public int getAardvarks() { return numAardvarks; } What is printed by the code segment? (A)0 (B)75 (C)The program compiles, but there is a logic error. (D)The program compiles, but there is a runtime error. (E)The program does not compile.

08.Consider the following code segment and List class. List list = new List(100,55); list.showList(); System.out.println(); class List { private int[] list; /* missing constructor */ public void showList() { for (int k = 0; k < list.length; k++) System.out.print(list[k] + " "); } The output of executing the code segment is a row of one hundred 55 numbers. Which of the following constructor implementations of /* missing constructor */ will make the List class work as intended? (A)public List(int size, int value) { list = new int[size]; for (int k = 0; k < size; k++) list[k] = value; } (B)public List() { list = new int[10]; for (int k = 0; k < size; k++) list[k] = 55; } (C)public List(int size, int value) { for (int k = 0; k < size; k++) list[k] = value; } (D)public List(int size, int value) { list = new int[size,value]; } (E)public List(int size, int value) { list = new int[size]; for (int k = 0; k <= size; k++) list[k] = value; }

09. Consider the following two classes and code segment. class Rumba { private Mambo dance; public Rumba() { System.out.println("Executing the Rumba constructor"); dance = new Mambo(); } class Mambo { public Mambo() { System.out.println("Executing the Mambo constructor"); } Mambo m = new Mambo(); Rumba r = new Rumba(); What is printed by the code segment? (A)Executing the Rumba constructor Executing the Mambo constructor (B)Executing the Mambo constructor Executing the Rumba constructor (C)Executing the Rumba constructor Executing the Mambo constructor Executing the Rumba constructor (D)Executing the Mambo constructor Executing the Rumba constructor Executing the Mambo constructor (E)Executing the Mambo constructor Executing the Mambo constructor Executing the Rumba constructor

10. The Boolean expression (A || B) && A is true (A)whenever A is true. (B)whenever B is true. (C)whenever either A is true or B is true. (D)whenever both A is true and B is true. (E)in all cases.

11. Consider the expression below. A || ( (B || !C) && (!D && F) || !(G && H) && !(!J || !K) ) If all you know is that A equals true, what can you determine about the expression above? (A)The expression evaluates to true. (B)The expression evaluates to false. (C)The expression evaluates to true only if B equals true. (D)The expression evaluates to true only if B equals false. (E)The expression cannot be evaluated with the provided information.

12. The Boolean expression !((A D)) is equivalent to which of the following expressions? (A)(A D) (B)(A >= B) && (C <= D) (C)(A >= B) || (C <= D) (D)(A > B) && (C < D) (E)(A > B) || (C < D)

13. Person sue = new Person(25); Student tom = new Student(17,12); System.out.println(sue.getAge()); System.out.println(tom.getGrade()); class Person { private int age; public Person(int a) { age = a; System.out.println("Person Constructor"); } public int getAge() { return age; } What are the first 2 lines of program output? (A)25 17 (B)Student Constructor Student Constructor class Student extends Person { private int grade; public Student(int g, int a) { super(a); grade = g; System.out.println("Student Constructor"); } public int getGrade() { return grade; } (C)Person Constructor Student Constructor (E)Student Constructor Person Constructor (E)Person Constructor Person Constructor

14. Person sue = new Person(25); Student tom = new Student(17,12); System.out.println(sue.getAge()); System.out.println(tom.getGrade()); class Person { private int age; public Person(int a) { age = a; System.out.println("Person Constructor"); } public int getAge() { return age; } What are the last 2 lines of program output? (A)25 17 (B)17 25 class Student extends Person { private int grade; public Student(int g, int a) { super(a); grade = g; System.out.println("Student Constructor"); } public int getGrade() { return grade; } (C)17 17 (D)25 25 (E)Person Constructor Student Constructor

15. Consider the following two classes and code segment. class Person { private int age; public Person(int a) { age = a; } public void showData() { System.out.println(age); } class Student extends Person { private int grade; public Student(int g, int a) { super(a); grade = g; } public void showData() { System.out.println(grade); super.showData(); } Person sue = new Person(25); Student tom = new Student(17,12); sue.showData(); tom.showData(); What is printed by the code segment? (A)25 17 (B)17 25 (C) (D)

16. Consider the following code segment. int[ ] list = {11,22,33,44,55,66,77,88,99}; for (int k = 0; k < list.length; k++) list[k] = list[k]/list[0]; for (int k = 0; k < list.length; k++) System.out.print(list[k] + " "); What is printed as a result of executing the code segment? (A) (B) (C) (D) (E)

17. int[ ] list1 = {10,20,30,40,50,60,70,80,90}; int[ ] list2 = list1; for (int k = 0; k < list2.length; k++) list2[k] = list1[0]; for (int k = 0; k < list1.length; k++) list1[k] *= list2[k]; for (int k = 0; k < list1.length; k++) System.out.print(list1[k] + " "); What is printed as a result of executing the code segment? (A) (B) (C) (D) 10 (E) 100

18. Consider the following code segment. double [ ][ ] values = new double[10][15]; int sum = 0; Each row in the array holds (in order) a student number, 10 homework grades of equal weight, and 4 exam grades. Choose the code segment below that would sum the homework grades in the sixth row and place them in the integer variable sum. (A) for (int j = 0; j < 15; j++) sum += values[6][j]; (B) for (int j = 0; j < 10; j++) sum += values[5][j]; (C) for (int j = 1; j < 11; j++) sum += values[j][6]; (D) for (int j = 0; j < 10; j++) sum += values[j][5]; (E) for (int j = 1; j < 11; j++) sum += values[5][j];

19. Consider the following code segment. ArrayList names = new ArrayList (); names.add("Isolde"); names.add("John"); names.add("Greg"); names.add("Maria"); names.add("Heidi"); names.add(2,"Diana"); names.add(5,"David"); System.out.println(names); What is printed as a result of executing the code segment? (A) [Isolde, John, Diana, Maria, Heidi, David] (B) [Isolde, Diana, Greg, Maria, David] (C) [Isolde, John, Diana, Greg, Maria, David, Heidi] (D) [Isolde, John, Diana, Greg, Maria, Heidi, David] (E) [Isolde, Diana, John, Greg, Maria, David, Heidi]

20. Consider the following code segment. ArrayList names = new ArrayList (); names.add("Isolde"); names.add("John"); names.add("Greg"); names.add("Maria"); names.add("Heidi"); names.set(2,names.get(3)); names.set(3,names.get(2)); System.out.println(names); What is printed as a result of executing the code segment? (A) [Isolde, John, Greg, Maria, Greg, Heidi] (B) [Isolde, John, Maria, Greg, Heidi] (C) [Isolde, John, Greg, Maria, Heidi] (D) [Isolde, John, Maria, Maria, Heidi] (E) [Isolde, Greg, John, Maria, Heidi]

21. Consider the following code segment. ArrayList names1 = new ArrayList (); names1.add("Isolde"); names1.add("John"); names1.add("Greg"); names1.add("Maria"); names1.add("Heidi"); ArrayList names2 = names1; names1.set(1,"Jessica"); names2.set(4,"Haley"); System.out.println(names1); System.out.println(names2); What is printed as a result of executing the code segment? (A)[Isolde, Jessica, Greg, Maria, Heidi] [Isolde, John, Greg, Maria, Haley] (B)[Isolde, Jessica, John, Greg, Maria, Heidi] [Isolde, John, Greg, Maria, Haley, Heidi] (C)[Isolde, John, Jessica, Greg, Maria, Heidi] [Isolde, John, Greg, Maria, Heidi, Haley] (D)[Isolde, John, Jessica, Greg, Maria, Haley, Heidi] [Isolde, John, Jessica, Greg, Maria, Haley, Heidi] (E)[Isolde, Jessica, Greg, Maria, Haley] [Isolde, Jessica, Greg, Maria, Haley]

22. Consider the following method. public static String method1(String str) { String temp = ""; int eSpot = str.indexOf('e'); temp = str.substring(0,eSpot); return temp; } What value does the method return if it is passed Entree as an argument? (A)An empty string (B)E (C)Entr (D)Entre (E)Entree

23. Consider the following code segment. String s1 = "Invalid"; String s2 = "valid"; s1 = s1.substring(2); boolean isSame; if (s1 == s2) isSame = true; else isSame = false; What is the value of isSame after the code segment executes? (A)True, because the two strings both hold the same value. (B)False, because the == operator compares immediate values, which are memory references for String objects. (C)Nothing, because using == to compare strings will give a run-time error. (D)True, because s1 and s2 now reference the exact same String object. (E)False, because s1 and s2 are not the same variable name.

24. Consider the following method. public static String method2(String[] values) { String temp = values[0]; for (int i = 1; i < values.length; i++) { if (values[i].compareTo(temp) > 0) temp = values[i]; } return temp; } What will the method return if the following array is sent as the argument? String[] arr = {"Math","Computer Science","Computer Applications","Science","Graphic Design"}; (A)"Math" (B)"Computer Science" (C)"Computer Applications" (D)"Science" (E)"Graphic Design"

25. Consider the following program. Car car = new Car("Ford250",350); class Engine { private int horsePower; public Engine(int hp) { horsePower = hp; } class Car { private Engine engine; private String carMake; /* MISSING CONSTRUCTOR */ } Question-25 continues on the next slide

25 continued. Which of the following implementations of MISSING CONSTRUCTOR will correctly initialize the instance variables of Engine and Car ? (A) public Car(String cm, int hp) { Engine engine = new Engine(hp); carMake = cm; } (B) public Car(String cm, int hp) { engine = new Engine(350); carMake = cm; } (C) public Car(String cm, int hp) { engine = new Engine(hp); carMake = cm; } (D) public Car(String carMake, int hp) { Engine = new Engine(hp); carMake = carMake; }

26. public class Test26 { public static void main(String args[]) { Pidgit p = new Pidgit(10,20); } class Widgit { private int numWidgits; public Widgit(int nw) { numWidgits = nw; } class Pidgit extends Widgit { private int numPidgits; private Widgit widgit; public Pidgit(int np, int nw) { numPidgits = np; widgit = new Widgit(nw); } What is the class interaction? (A)Inheritance (B)Composition (C)Both inheritance & composition (D)No class interaction (E)Improper class interaction

27. Consider this is a partial BoundedGrid class declaration. public class BoundedGrid extends AbstractGrid { private Object[ ][ ] occupantArray; public BoundedGrid(int rows, int cols) { if (rows <= 0) throw new IllegalArgumentException("rows <= 0"); if (cols <= 0) throw new IllegalArgumentException("cols <= 0"); occupantArray = new Object[rows][cols]; } The BoundedGrid class uses a _______________ array to store data. (A)generic, two-dimensional (B)static, two-dimensional (C)dynamic, two-dimensional (D)generic, one-dimensional array (E)dynamic, one-dimensional array

28. Consider the following code segment. String[ ] stID = {"ABC", "DEF", "GHI", "JKL", "MNO"}; String str1 = "GHI"; boolean found = false; int loc = -1, sub = 0; while (!found && sub < stID.length) { if (stID[sub].equals(str1)) { found = true; loc = sub; } sub++; } The code segment is an example of (A)a sort algorithm. (B) an algorithm to locate the smallest element. (C) an algorithm to locate the largest element. (D) a sequential search algorithm. (E) an algorithm to sum the values of an array.

29. When using a binary search, what is the MAXIMUM number of comparisons necessary to locate a specific item in a list of 1025 elements? (A)1 (B) 9 (C) 10 (D) 11 (E) 1024

30. Consider the following array: int[ ] array = {4, 8, 2, 7, 1, 9, 3, 5}; What would array hold after three iteration passes of the outer loop in an ascending selection sort algorithm? (A){1, 2, 3, 4, 8, 7, 9, 5} (B){2, 4, 7, 8, 1, 9, 3, 5} (C){1, 2, 3, 7, 4, 9, 8, 5} (D){4, 2, 7, 8, 1, 9, 3, 5} (E){4, 3, 2, 5, 1, 7, 8, 9}

34.Consider the following GridWorld display. How many Bug objects will be left after the next Step iteration? (A)1 bug (B)2 bugs (C)3 bugs (D)4 bugs (E)5 bugs

35. Consider the following MysteryCritter class. class MysteryCritter extends Critter { public void turn() { int add = (int) (Math.random()*91)+90); setDirection(getDirection() + add); } How many degrees will a MysteryCritter object turn during one step of a GridWorld execution? (A)0 (B)90 (C)180 (D)A random number in the range of (E)A random number in the range

36. You are asked to implement a new GridWorld class, called DynamiteCritter. DynamiteCritter objects act exactly like Critter objects, except that they only process Rock objects by blowing them up. Implementing this new DynamiteCritter class will require re-defining (A)all the act methods. (B)the getActors method only. (C) the processActors method only. (D)methods getActors and processActors only. (E)methods getMoveLocations, selectMoveLocation and makeMove only.

37.Consider the following code segment from the step method used by the ActorWorld class. The step method is called each time the Step button is clicked on the Gridworld display or repeatedly after the Run button is clicked. for (Actor a : actors) { if (a.getGrid() == gr) a.act(); } Which of the following statements completes a correct explanation how the loop executes, shown above? Every object which occupies a cell on the current grid, when the step method is called, will execute according to the act method definition of (A)the Actor class. (B)its own class. (C)its own class, provided the object is still a member of the grid. (D)its own class or a superclass. (E)its own class or a superclass, provided the object is still a member of the grid.

38.Consider the following class definitions and code segment. ClassA item1 = new ClassA(); ClassA item2 = new ClassB(); ClassA item3 = new ClassC(); item1.method(10); item2.method(20); item3.method(30); class ClassA { public ClassA() { } public void method(int a) {System.out.println("Class A " + a);} } class ClassB extends ClassA { public ClassB(){ } public void method(int b) {System.out.println("Class B " + b);} } class ClassC extends ClassB { public ClassC(){ } } What is printed as a result of executing the code segment? (A)Class A 10 Class A 20 Class A 30 (B)Class A 10 Class B 20 Class B 30 (C)Class A 10 Class B 20 (D)Class A 10 Class B 20 (E)Exception error message

39.Consider the following interface, two classes and incomplete code segment. abstract interface Shape { public abstract double getArea(); } class Circle implements Shape { private double radius; public Circle (double r){radius = r;} public double getArea(){return Math.PI * radius * radius;} } class Triangle implements Shape { private double base; private double height; public Triangle (double b, double h){base = b; height = h;} public double getArea(){return (base * height) / 2;} } Shape[ ] shapes = new Shape[2]; shapes[0] = new Circle(3); shapes[1] = new Triangle(4,3); /* missing code segment */ Question-39 continues on the next slide.

Question 39 Continued. Which of the following implementations of /* missing code segment */ will correctly display the areas of the shapes array elements. Implementation I: for (int k = 0; k < shapes.length; k++) System.out.println(shapes[k].getArea()); Implementation II: for (Shape s: shapes) System.out.println(s.getArea()); Implementation III: for (int k = 0; k < shapes.length; k++) if (shapes[k] instanceof Circle) System.out.println(Circle.getArea()); else if (shapes[k] instanceof Triangle) System.out.println(Triangle.getArea()); (A)Implementation I only (B)Implementation III only (C)Implementations I & II only (D)Implementations II & III only (E)Implementations I, II & III

40.Consider the following code segment. String[] list1 = {"Tom","Sue","Joe"}; ArrayList list2 = new ArrayList (); list2.add("Meg"); list2.add("Bob"); list2.add("Ann"); System.out.println(list1); System.out.println(list2); What is printed as a result of executing the code segment? (A)[Tom, Sue, Joe] [Meg, Bob, Ann] (B)[Tom, Sue, Joe] [Ljava.util.ArrayList:memory reference (C)[Ljava.lang.String:memory reference [Meg, Bob, Ann] (D)[Ljava.lang.String:memory reference [Ljava.util.ArrayList:memory reference (E)None of the above, because array objects can only be displayed with a loop structure, which accesses each array element.

41. Consider the following code segment and Car class. Car car = new Car("Ford",2010); System.out.println(car); class Car { private String make; private int year; public Car (String m, int y) { make = m; year = y; } public String toString () { return "[" + make + ", " + year + "]"; } What is printed as a result of executing the code segment? (A)[Ford, 2010] (B)[make, year] (C)Ford, 2010 (E)None of the above

42.Consider the following code segment and Car class. Car car1 = Car car2 = System.out.println (car1.equals(car2)); class Car { private String make; private int year; public Car (String m, int y) { make = m; year = y; } public boolean equals (Object other) { return true; } What is printed as a result of executing the code segment? (A)False, since non-standard classes cannot be compared for equality. (B)Neither, since output cannot be determined without specific Car object information (C)True, if both objects are the same year (D)True, if both objects are both the same make and the same year (E)True, for all Car objects

43. When a class implements an interface, what must it do? (A)It must redefine each constant from the interface. (B)It must declare and provide a method body for each method in the interface. (C)It must declare a variable for each constant in the interface. (D)It must declare abstract methods for each method in the interface (E)It must include a private method for each method in the interface.

44. Consider the following erroneous interface and class definition. /*1*/ public interface Interface1 /*2*/ { /*3*/public int FIELDA = 55; /*4*/public int methodA(double d); /*5*/ } /*6*/ public class ClassA implements Interface1 /*7*/ { /*8*/public int FIELDA = 60; /*9*/public int methodA(double a) /*10*/{ return (int) a; } /*11*/} Which line contains an error? (A)Line 3, because variables in interfaces require the final keyword (B)Line 4, because there should not be a semicolon at the end of the method header (C)Line 8, because FIELDA cannot be modified here (D)Line 9, because the name of the parameter is different from Line 4 (E)Line 10, because it is illegal to cast a double to an int

45. Why is there an abstract class implementation, which partially implements the Grid interface methods, followed by BoundedGrid and UnboundedGrid classes, which completely implement the Grid interface? (A)A class cannot implement an abstract interface. Only an abstract class can implement an abstract interface. (B)An abstract class must be used when there are multiple class that implement interface methods. (C)BoundedGrid and UnboundedGrid implement some Grid interface methods differently. All the methods that have an identical implementation for BoundedGrid and UnBoundedGrid are implemented in the AbstractGrid class. (D)Abstract classes give greater readability than concrete classes. (E)The use of polymorphism requires abstract class implementation of an interface.

46. A team of programmers works together on a large project. Each team member is assigned to create, write and test one class that will be used in the project. Which of the following is the minimal required information for each programmer to start his/her assigned task? I.The data that will need to be stored by the class. II.The method signatures that will access the class data. III.The preconditions and postconditions of each class method (A)I only (B)II only (C)I and II only (D)II and III only (E)I, II and III

47.Consider the following code segment. ArrayList list1 = new ArrayList (); /* program code that enters appropriate values to the list1 object */ ArrayList list2 = list1; /* code statements to perform various processing functions */ The completed code has some potential problems that can negatively impact program reliability. Which of the following are potential problems? I.An ArrayOutOfBoundsException will occur. II.list2 makes a shallow copy of list1, which can result in unwanted changes to the state of list1 or list2. III.list2 is never constructed with the new operator. (A)I only (B)II only (C)III only (D)I and II only (E)I and III only

48.A data structure needs to store information in about 20,000 college student records. A variety of information needs to be stored in each student record, such as name, age, gpa, date of birth, address and social security number. The data structure is to be used in a program with the following two data processing requirements: [1]Frequent quick access to any student records to update student information. [2]End-of-semester access to print a student GPA list from highest to lowest. Consider the following two implementations to satisfy the two processing requirements. Implementation-1 stores all the student records in a data structure that is sorted according to GPA so as to allow efficient printing of a GPA list, but a linear search is required to access any individual student information according to social security number. Implementation-2 stores all the student records in a data structure that is sorted according to student social security number. The data structure must be sorted according to GPA before a sorted GPA list can be printed. Question-48 continues on the next slide.

Question 48 Continued. Which of the following statements is true about the manner in which Implementation-1 and Implementation-2 satisfy the two data processing requirements? (A)Implementation-1 is better, because it keeps the data sorted, such that all 20,000 records can be easily printed according to GPA order. (B)Implementation-1 is better, because it takes longer to sort records than it takes to search for one specific record. (C)Implementation-2 is better, because frequent searches take longer than occasional sorting. (D)Implementation-2 is better, because frequent sorting take longer than occasional searching. (E)Implementation-1 and Implementation-2 are essentially identical and each works as efficiently as the other does.