MC Question Strategies

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

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 =
First Data Structure Definition A data structure is a data type whose components are smaller data structures and/or simple data types.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-1: Arrays reading: 7.1 self-checks: #1-9 videos: Ch. 7 #4.
What’s in a Language naming objects (variables) naming processes (methods/functions) making decisions (if) making repetitions (for, while) (recursion)
Midterm Test Overview CS221 – 3/23/09. Test Curve Current median is a 71 or C- Median will be adjusted to an 81 or B- All test scores will be +10 on.
Inheritance Inheritance is the process of using features (both attributes and methods) from an existing class. The existing class is called the superclass.
Recursion & Collections API Recursion Revisited Programming Assignments using the Collections API.
Review of Simple/Primitive Data Types A simple/primitive data type can store only one single value. This means an int can only store one integer. A double.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
Applications of Arrays (Searching and Sorting) and Strings
First Data Structure Definition A data structure is a data type whose components are smaller data structures and/or simple data types.
Introduction Chapter 12 introduced the array data structure. Historically, the array was the first data structure used by programming languages. With.
Inheritance Inheritance is the process of using features (both attributes and methods) from an existing class. The existing class is called the superclass.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 5 Generic.
Method Overloading  Methods of the same name can be declared in the same class for different sets of parameters  As the number, types and order of the.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Output Programs These slides will present a variety of small programs. Each program has some type of array that was introduced in this chapter. Our concern.
Review of Simple/Primitive Data Types A simple/primitive data type can store only one single value. This means an int can only store one integer. A.
Introduction Chapter 12 introduced the array data structure. Historically, the array was the first data structure used by programming languages. With.
1 CSE 142 Final Exam Review Problems. 2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes.
Algorithm Definition An algorithm is a step-by-step solution to a problem.
Algorithm Definition An algorithm is a step-by-step solution to a problem.
Algorithm Definition An algorithm is a step-by-step solution to a problem.
2 Arrays Array is a data structure that represents a collection of the same type of data. A "fixed length list".
Building Java Programs Chapter 7 Arrays Copyright (c) Pearson All rights reserved.
Topic 21 arrays - part 1 Copyright Pearson Education, 2010 Based on slides by Marty Stepp and Stuart Reges from "Should.
Exposure Java 2011 APCS Edition
PowerPoint Presentation Authors of Exposure Java
Exposure Java 2014 APCS Edition
Bill Tucker Austin Community College COSC 1315
Software Development Java Classes and Methods
More on Recursion.
Lecture 17: Polymorphism (Part II)
Arrays! Introduction to Data Structures.
Specifications What? Not how!.
SELECTION STATEMENTS (1)
Building Java Programs
Building Java Programs
Chapter 10 Slides Java Static 1D & 2D Arrays.
2/26/12 Quiz Bowl.
Building Java Programs Chapter 7
Section 11.1 Introduction to Data Structures.
Adapted from slides by Marty Stepp, Stuart Reges & Allison Obourn.
Data Structures ADT List
Section 13.1 Introduction.
Building Java Programs
Section 11.1 Introduction to Data Structures.
Outline Late Binding Polymorphism via Inheritance
Building Java Programs
Building Java Programs
Building Java Programs
Topic 5 Polymorphism "“Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.”
Data Structures (CS212D) Week # 2: Arrays.
Arrays Week 2.
Recursion Problems.
Take out a piece of paper and PEN.
PowerPoint Presentation Authors of Exposure Java
CIS 199 Final Review.
PowerPoint Presentation Authors of Exposure Java
CSC 143 Binary Search Trees.
Take out a piece of paper and PEN.
Building Java Programs
Building Java Programs
Question 1a) What is printed by the following Java program? int s;
Consider Write a program that prompts a user to enter the number of students and then, their names and grades. The program will then outputs the average.
Building Java Programs
Two-Dimensional Arrays
Objects with ArrayLists as Attributes
First Semester Review.
Presentation transcript:

MC Question Strategies Snooker Questions By Leon Schram, Plano Texas

Control Structures

01. Consider the following code segment.   int x = <some integer greater than zero> int n = 0; if (x < 500) { if (x > 750) n = 100; else n = 200; } if (x < 300) n = 300; 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

01. Consider the following code segment.   int x = <some integer greater than zero> int n = 0; if (x < 500) { if (x > 750) n = 100; else n = 200; } if (x < 300) n = 300; 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 count = 10; for (int p = 0; p < 15; p+=3) { if (p % 2 == 0) count++; se 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

02. 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

Methods & Parameters

03. Consider the following program.   public class Question03 { 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) 10 10 (D) 20 20 (E) 0 0

03. Consider the following program.   public class Question03 { 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) 10 10 (D) 20 20 (E) 0 0

04. Consider the following program.   public class Question04 { 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 (D) 5 4 (E) ArrayIndexOutOfboundsException

04. Consider the following program.   public class Question04 { 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 (D) 5 4 (E) ArrayIndexOutOfboundsException

Boolean Logic

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

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

06. Consider the following code segment.   for (int k = 1; k <= 100; k++) { int n1 = (int) Math.random(); int n2 = (int) Math.random() * 4; boolean bool = n1 == n2; System.out.print(bool + " "); } What is printed as a result of executing the code segment?   (A) The code segment always prints true. (B) The code segment always prints false. (C) The code segment prints true roughly 25% of the time and prints false roughly 75% of the time. (D) The code segment prints both true and false, but true more frequently. (E) The code segment prints both true and false, but false more frequently.

06. Consider the following code segment.   for (int k = 1; k <= 100; k++) { int n1 = (int) Math.random(); int n2 = (int) Math.random() * 4; boolean bool = n1 == n2; System.out.print(bool + " "); } What is printed as a result of executing the code segment?   (A) The code segment always prints true. (B) The code segment always prints false. (C) The code segment prints true roughly 25% of the time and prints false roughly 75% of the time. (D) The code segment prints both true and false, but true more frequently. (E) The code segment prints both true and false, but false more frequently.

OOP Inheritance

(C) Person Constructor Student Constructor (E) Student Constructor 07. 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;    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 What are the first 2 lines of program output?    (A) 25 17   (B) Student Constructor Student Constructor

(C) Person Constructor Student Constructor (E) Student Constructor 07. 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;    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 What are the first 2 lines of program output?    (A) 25 17   (B) Student Constructor Student Constructor

(E) Person Constructor Student Constructor 08. 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;    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 What are the last 2 lines of program output?    (A) 25 17   (B) 17 25 

(E) Person Constructor Student Constructor 08. 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;    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 What are the last 2 lines of program output?    (A) 25 17   (B) 17 25 

Static Arrays

09. 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]; System.out.print(list[k] + " "); What is printed as a result of executing the code segment?   (A) 11 22 33 44 55 66 77 88 99 (B) 1 2 3 4 5 6 7 8 9 (C) 1 1 1 1 1 1 1 1 1 (D) 1 22 33 44 55 66 77 88 99 (E) 11 22 33 44 55 66 77 88 9

09. 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]; System.out.print(list[k] + " "); What is printed as a result of executing the code segment?   (A) 11 22 33 44 55 66 77 88 99 (B) 1 2 3 4 5 6 7 8 9 (C) 1 1 1 1 1 1 1 1 1 (D) 1 22 33 44 55 66 77 88 99 (E) 11 22 33 44 55 66 77 88 9

10. Consider the following code segment.   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]; System.out.print(list1[k] + " "); What is printed as a result of executing the code segment?   (A) 100 100 100 100 100 100 100 100 100 (B) 100 200 300 400 500 600 700 800 900 (C) 1 2 3 4 5 6 7 8 9 (D) 10 (E) 100

10. Consider the following code segment.   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]; System.out.print(list1[k] + " "); What is printed as a result of executing the code segment?   (A) 100 100 100 100 100 100 100 100 100 (B) 100 200 300 400 500 600 700 800 900 (C) 1 2 3 4 5 6 7 8 9 (D) 10 (E) 100

Dynamic Arrays

11. Consider the following code segment.   ArrayList<String> names = new ArrayList<String>(); 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]

11. Consider the following code segment.   ArrayList<String> names = new ArrayList<String>(); 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]

12. Consider the following method.   /** Precondition: list contains [13, 64, 42, 27, 77, 38, 11] */ public static void mystery(ArrayList<Integer> list) { for (int k = 0; k < list.size(); k++) if (list.get(k) % 2 == 0) list.remove(k); } Which of the following describes the values stored in list after mystery executes?   (A) [13, 64, 42, 27, 77, 38, 11] (B) [13, 27, 77, 11] (C) [13, 42, 27, 77, 11] (D) [64, 42, 38] An IndexOutOfBoundsException error message

12. Consider the following method.   /** Precondition: list contains [13, 64, 42, 27, 77, 38, 11] */ public static void mystery(ArrayList<Integer> list) { for (int k = 0; k < list.size(); k++) if (list.get(k) % 2 == 0) list.remove(k); } Which of the following describes the values stored in list after mystery executes?   (A) [13, 64, 42, 27, 77, 38, 11] (B) [13, 27, 77, 11] (C) [13, 42, 27, 77, 11] (D) [64, 42, 38] An IndexOutOfBoundsException error message

String Methods

13. Consider the following method.   // Precondition: str is a nonempty string of upper-case letters public static String mystery(String str) { String temp = ""; for (int k = 0; k < str.length(); k++) String t = str.substring(k,k+1); if (t != "A" || t != "E" || t != "I" || t != "O" || t != "U") temp += t; } return temp; Which of the following is a correct Postcondition, based on the return of method mystery?   (A) Postcondition: mystery returns str (B) Postcondition: mystery returns str with all vowels removed (C) Postcondition: mystery returns only the vowels in str (D) Postcondition: mystery returns null (E) It will generate a StringOutOfBoundsException error message

13. Consider the following method.   // Precondition: str is a nonempty string of upper-case letters public static String mystery(String str) { String temp = ""; for (int k = 0; k < str.length(); k++) String t = str.substring(k,k+1); if (t != "A" || t != "E" || t != "I" || t != "O" || t != "U") temp += t; } return temp; Which of the following is a correct Postcondition, based on the return of method mystery?   (A) Postcondition: mystery returns str (B) Postcondition: mystery returns str with all vowels removed (C) Postcondition: mystery returns only the vowels in str (D) Postcondition: mystery returns null (E) It will generate a StringOutOfBoundsException error message

14. What is the output of the following program segment? String s = “Mississippi”; System.out.println(s.indexOf(s.substring(5,7));   1 2 (C) 4 5 7

14. What is the output of the following program segment? String s = “Mississippi”; System.out.println(s.indexOf(s.substring(5,7));   1 2 (C) 4 5 7

Program Algorithms

15. 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.

15. 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.

16. 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

16. 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

Recursive Methods

17. Consider the following code segment and method. int[ ] list = {1,2,3,4}; mystery1(list,0); public static void mystery1(int[ ] x, int n) { if (n < x.length) System.out.print(x[n] + " "); mystery1(x,n+1); } What is output by executing the code segment?  (A) 1 2 3 4 (B) 1 2 3 (C) 4 3 2 1 (D) 3 2 1 0 (E) 3 2 1

17. Consider the following code segment and method. int[ ] list = {1,2,3,4}; mystery1(list,0); public static void mystery1(int[ ] x, int n) { if (n < x.length) System.out.print(x[n] + " "); mystery1(x,n+1); } What is output by executing the code segment?  (A) 1 2 3 4 (B) 1 2 3 (C) 4 3 2 1 (D) 3 2 1 0 (E) 3 2 1

18. Consider the following code segment and method. int[ ] list = {1,2,3,4}; mystery2(list,0); public static void mystery2(int[ ] x, int n) { if (n < x.length) mystery2(x,n+1); System.out.print(x[n] + " "); } What is output by executing the code segment?  (A) 1 2 3 4 (B) 1 2 3 (C) 4 3 2 1 (D) 3 2 1 0 (E) 3 2 1

18. Consider the following code segment and method. int[ ] list = {1,2,3,4}; mystery2(list,0); public static void mystery2(int[ ] x, int n) { if (n < x.length) mystery2(x,n+1); System.out.print(x[n] + " "); } What is output by executing the code segment?  (A) 1 2 3 4 (B) 1 2 3 (C) 4 3 2 1 (D) 3 2 1 0 (E) 3 2 1

19. Consider the following code segment and method. System.out.println(mystery3(5)); public static int mystery3(int n) { if (n == 0) return n; else return n + mystery3(n-1); } What value is returned by the a call to mystery3(5)?    (A) 4 (B) 8 (C) 12 (D) 15 (E) 16

19. Consider the following code segment and method. System.out.println(mystery3(5)); public static int mystery3(int n) { if (n == 0) return n; else return n + mystery3(n-1); } What value is returned by the a call to mystery9(5)?    (A) 4 (B) 8 (C) 12 (D) 15 (E) 16

20. Consider the following code segment and method. System.out.println(mystery4(5)); public static int mystery4(int n) { if (n == 1) return 1; else return mystery4(n-1) + mystery4(n-1); } What value is returned by the a call to mystery4(5)?    (A) 16 (B) 15 (C) 8 (D) 7 (E) 4

20. Consider the following code segment and method. System.out.println(mystery4(5)); public static int mystery4(int n) { if (n == 1) return 1; else return mystery4(n-1) + mystery4(n-1); } What value is returned by the a call to mystery4(5)?    (A) 16 (B) 15 (C) 8 (D) 7 (E) 4

21. Consider the following code segment and method. System.out.println(mystery5(4)); public static int mystery5(int n) { if (n == 1) return 1; else return n + mystery5(n-1) + mystery5(n-1); } What value is returned by the a call to mystery5(5)?    (A) 13 (B) 25 (C) 26 (D) 32 (E) 34

21. Consider the following code segment and method. System.out.println(mystery5(4)); public static int mystery5(int n) { if (n == 1) return 1; else return n + mystery5(n-1) + mystery5(n-1); } What value is returned by the a call to mystery5(5)?    (A) 13 (B) 25 (C) 26 (D) 32 (E) 34

OOP Polymorphism

What is printed as a result of executing the code segment? 22. 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 (D) Class A 10 (E) Exception error message

What is printed as a result of executing the code segment? 22. 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 (D) Class A 10 (E) Exception error message

Redefining Methods

23. Consider the following code segment.   String[] list1 = {"Tom","Sue","Joe"}; ArrayList<String> list2 = new ArrayList<String>(); 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 (E) None of the above, because array objects can only be displayed with a loop structure, which accesses each array element.

23. Consider the following code segment.   String[] list1 = {"Tom","Sue","Joe"}; ArrayList<String> list2 = new ArrayList<String>(); 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 (E) None of the above, because array objects can only be displayed with a loop structure, which accesses each array element.

24. 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 (D) Car@<some memory reference> (E) None of the above

24. 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 (D) Car@<some memory reference> (E) None of the above

25. Consider the following code segment and Car class.   Car car1 = <some Car object> Car car2 = <some Car object> 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

25. Consider the following code segment and Car class.   Car car1 = <some Car object> Car car2 = <some Car object> 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