CS 18000GLD - Final Review

Ace your homework & exams now with Quizwiz!

A class can have multiple methods with the same name. A) True B) False

A class can have multiple methods with the same name. A) True

A class can implement multiple interfaces. A) True B) False

A class can implement multiple interfaces. A) True

After evaluating the following statements, which option is correct? ---------------------------- boolean a = true && false; boolean b = true || false; A) a will be false B) Both a and b will be true C) a will be true D) b will be false E) Both a and b will be false

After evaluating the following statements, which option is correct? ---------------------------- boolean a = true && false; boolean b = true || false; A) a will be false

An algorithm is A) the computational time complexity of a program. B) the thread running the main method of a program. C) the memory segment holding references to objects. D) a step by step series of instructions to solve a problem. E) a synonym for encapsulation

An algorithm is D) a step by step series of instructions to solve a problem.

Given the declaration: ---------------------------- int[][] a = {{2}, {6,8,10}, {0,4}}; ---------------------------- Which of the following statements both compiles and executes without error? A) a[1][3] = a[3][1]; B) a[2][3] = a[3][2]; C) a[1][2] = a[2][1]; D) a[0][1] = a[1][0]; E) a[2][0] = a[0][2];

Given the declaration: ---------------------------- int[][] a = {{2}, {6,8,10}, {0,4}}; ---------------------------- Which of the following statements both compiles and executes without error? C) a[1][2] = a[2][1];

How many base cases does a well-defined recursive function have? A) 1 B) 5 C) At most 3 D) At least 1 E) 3

How many base cases does a well-defined recursive function have? D) At least 1

If no access modifier is specified on a class, field or method, it defaults to public. A) True B) False

If no access modifier is specified on a class, field or method, it defaults to public. B) False

If one wanted to compile a file called fileA.java into a Java executable using the command line, which of the following commands would they execute? Assume that the user is already inside the src folder. A) javac fileA.java B) javac fileA C) jshell fileA.java D) javac fileA.class E) javac fileA

If one wanted to compile a file called fileA.java into a Java executable using the command line, which of the following commands would they execute? Assume that the user is already inside the src folder. A) javac fileA.java

In Java an abstract class cannot extend another abstract class. A) True B) False

In Java an abstract class cannot extend another abstract class. B) False

JVM is the acronym for A) Java Virtual Memory B) Java Visual Machine C) Java Visual Memory D) Java Virtual Machine E) Java Vendor Machine

JVM is the acronym for D) Java Virtual Machine

Static binding occurs at A) Compilation time B) None of the options are valid. C) Run time D) Data transfer time E) Program Storage time

Static binding occurs at A) Compilation time

What is causing the following code to not compile? ---------------------------- void somethingIsWrong(int withThisMethod) { int num = 1.0; num++; num += 20; num -= 0; System.out.printf("%d", num); } A) I. The variable num cannot be initialized to a value of 1.0. B) II. The System.out.printf("%d", num) statement cannot be used with "%d". C) III. The method does not have a scope modifier. D) Both (I) and (II). E) There is nothing wrong with the above method.

What is causing the following code to not compile? ---------------------------- void somethingIsWrong(int withThisMethod) { int num = 1.0; num++; num += 20; num -= 0; System.out.printf("%d", num); } A) I. The variable num cannot be initialized to a value of 1.0.

What is the method signature of the makeMatrix method? ----------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } A) static int[][] int[], int[] B) static int[][] makeMatrix() C) static int[][] makeMatrix(int[], int[]) throws ArrayIndexOutOfBoundsException D) static int[][] makeMatrix(int[], int[]) E) makeMatrix(int[] , int[])

What is the method signature of the makeMatrix method? ----------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } E) makeMatrix(int[] , int[])

What is the output of the following code snippet? ----------------------------- int x, y = 5; double z = 20.0; int result = x + (y / z); System.out.println(result); A) Compile time error: the first line of code needs to be split into two lines of code B) 0 C) 5.25 D) 5 E) Compile time error: x is not initialized

What is the output of the following code snippet? ----------------------------- int x, y = 5; double z = 20.0; int result = x + (y / z); System.out.println(result); E) Compile time error: x is not initialized

What is the programming language used in the CS18000 Course at Purdue University? A) Ruby on Rails B) JavaScript C) Java D) C E) Python

What is the programming language used in the CS18000 Course at Purdue University? C) Java

What will be the value of x after the execution of the following code segment? ---------------------------- int x = 3; switch(x - 1) { case 1: x += 4; case 2: x = 1; case 3: case 4: x /= 3; case 5: x++; break; case 6: x *= 4; default: x = 2; } A) 2 B) 3 C) 4 D) 5 E) 1

What will be the value of x after the execution of the following code segment? ---------------------------- int x = 3; switch(x - 1) { case 1: x += 4; case 2: x = 1; case 3: case 4: x /= 3; case 5: x++; break; case 6: x *= 4; default: x = 2; } E) 1

What will the following code snippet print? ---------------------------- String s = "ALICIA"; System.out.println(s.indexOf('I') + 3); A) 4 B) L C) 5 D) Error: String index out of range E) A

What will the following code snippet print? ---------------------------- String s = "ALICIA"; System.out.println(s.indexOf('I') + 3); C) 5

When reading from a file, the file must exist. A) True B) False

When reading from a file, the file must exist. A) True

When writing to a file, the file must exist. A) True B) False

When writing to a file, the file must exist. B) False

Which of the following statement(s) is/are incorrect? I. PrintWriter will always overwrite the contents of the file. II. BufferedReader can be used to write across a network stream III. BufferedWriter can only be used with files. A) I, II, and III B) I and II C) I only D) III only E) None of the options are incorrect.

Which of the following statement(s) is/are incorrect? I. PrintWriter will always overwrite the contents of the file. II. BufferedReader can be used to write across a network stream III. BufferedWriter can only be used with files. A) I, II, and III

Which of the following statements correctly checks if a String object str is null? A) I. if (str == null) B) II. if (str = null) C) III. if (str.equals(null)) D) Both (I) and (III). E) IV. if (str.length == 0)

Which of the following statements correctly checks if a String object str is null? A) I. if (str == null)

What is a proxy method? A. A recursive method. B. A non-recursive method that calls the recursive method. C. The last method called in a recursive sequence. D. A method that calls itself sometimes, but not all the time. E. A method with no parameters.

[November 30 - Quiz 37] B. A non-recursive method that calls the recursive method. ----------------------------- A. A recursive method. --> A proxy method is not recursive. [B. CORRECT] C. The last method called in a recursive sequence. --> No. That's a recursive method. D. A method that calls itself sometimes, but not all the time. --> No. That's a recursive method. E. A method with no parameters. --> No. That's a 0-parameter method.

Consider the following code snippet: ---------------------------- public static int euclid(int a, int b) { if (b == 0) { return a; } return euclid(b, a % b); } ---------------------------- What will the above code result in, given the method call euclid(105, 30)? A) 15 B) 30 C) 35 D) 5 E) 105

Consider the following code snippet: ---------------------------- public static int euclid(int a, int b) { if (b == 0) { return a; } return euclid(b, a % b); } ---------------------------- What will the above code result in, given the method call euclid(105, 30)? A) 15

Consider the following constructor for a Course object: ---------------------------- public Course(String name, String department, int credits) { this.name = name; // The unique name of the course. this.department = department; // The department it belongs to this.credits = credits; // The credits earned from this course } ---------------------------- Which of the following statements should be used to determine if two Course objects c1 and c2 are identical? Assume each of the fields above has an accessor method, and no values are null. A) if (c1.getCredits() == c2.getCredits()) B) if (c1.getCredits() == c2.getCredits() && c1.getName() == c2.getName()) C) if (c1.getName() == c2.getName()) D) if (c1 == c2) E) if (c1.getName().equals(c2.getName()))

Consider the following constructor for a Course object: ---------------------------- public Course(String name, String department, int credits) { this.name = name; // The unique name of the course. this.department = department; // The department it belongs to this.credits = credits; // The credits earned from this course } ---------------------------- Which of the following statements should be used to determine if two Course objects c1 and c2 are identical? Assume each of the fields above has an accessor method, and no values are null. E) if (c1.getName().equals(c2.getName()))

Consider the following lines of code: ----------------------------- int a = 31; int b = 16; int c = 1; int d = 2; int e = b + c * d - a / b / d; ----------------------------- What is the value stored in e? A) 0 B) 18 C) 17 D) 1 E) 15

Consider the following lines of code: ----------------------------- int a = 31; int b = 16; int c = 1; int d = 2; int e = b + c * d - a / b / d; ----------------------------- What is the value stored in e? B) 18

Consider the main method below: ----------------------------- public static void main(String[] args) { String str = "Some Text!"; String expected = "some text is here!"; //INSERT CODE HERE System.out.println("Expected: " + expected); System.out.println("Actual: " + str); } ----------------------------- Which of the following lines, when inserted, will result in an output of the following: Actual: some text is here! A) str = str.substring(0, str.length() - 1).toLowerCase().concat("" is here!""); B) str = str.toLowerCase().concat("" is here!""); C) str = str.toLowerCase().substring(0); D) str = str.concat("" is here!""); E) str = str.toLowerCase().repeat("" is here!"");

Consider the main method below: ----------------------------- public static void main(String[] args) { String str = "Some Text!"; String expected = "some text is here!"; //INSERT CODE HERE System.out.println("Expected: " + expected); System.out.println("Actual: " + str); } ----------------------------- Which of the following lines, when inserted, will result in an output of the following: Actual: some text is here! A) str = str.substring(0, str.length() - 1).toLowerCase().concat("" is here!"");

Every class in Java possesses the toString() method (even if it is not explicitly defined) due to which of the following reasons? A) Every class extends the String class. B) Every class extends the Object class. C) Every class extends the Parent class. D) None of the options are valid. E) All of the options are valid.

Every class in Java possesses the toString() method (even if it is not explicitly defined) due to which of the following reasons? B) Every class extends the Object class.

Examine the following code snippet: ---------------------------- String str = "text to substring from"; str.substring(18); System.out.println(str); ---------------------------- What will the code snippet print? A) text to substring from B) substring from C) from D) Runtime Error. E) It will print something else.

Examine the following code snippet: ---------------------------- String str = "text to substring from"; str.substring(18); System.out.println(str); ---------------------------- What will the code snippet print? A) text to substring from

How many times does the following loop iterate? ----------------------------- for (double i = 1/8; i < 1; i *= 2) { //Do something } A) 3 B) 6 C) Infinite loop D) 8 E) 4

How many times does the following loop iterate? ----------------------------- for (double i = 1/8; i < 1; i *= 2) { //Do something } C) Infinite loop

How many times will the following loop execute? ---------------------------- for (int i = 0; i < 10; i--) { //something quite fun happens here :) } A) None of the options are valid. B) One time C) An infinitely large number of times. D) The loop will never begin. E) Ten times

How many times will the following loop execute? ---------------------------- for (int i = 0; i < 10; i--) { //something quite fun happens here :) } A) None of the options are valid.

In which of the following classes is the clone() method defined? A) Object B) From the class that you write the implementation in. C) File D) Enum E) String

In which of the following classes is the clone() method defined? A) Object

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- Given the following main method, what will the output be? ---------------------------- public static void main(String[] args) { Pokemon monkey = new Chimchar(""); monkey.evolve(); monkey = monkey.evolve(); monkey = monkey.evolve(); System.out.println(monkey.toString()); } A) Monferno[Monferno] B) Monferno[Chimchar] C) Infernape[Chimchar] D) Infernape[Infernape] E) Chimchar[Chimchar]

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- Given the following main method, what will the output be? ---------------------------- public static void main(String[] args) { Pokemon monkey = new Chimchar(""); monkey.evolve(); monkey = monkey.evolve(); monkey = monkey.evolve(); System.out.println(monkey.toString()); } C) Infernape[Chimchar]

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- If the toString method in class Infernape did not exist, what would the invocation of the method result in? Assume that the Infernape object did not have a nickname. A) Chimchar[Infernape] B) Infernape[?] C) Monferno[Monferno] D) NullPointerException thrown E) Pokemon[?]

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- If the toString method in class Infernape did not exist, what would the invocation of the method result in? Assume that the Infernape object did not have a nickname. E) Pokemon[?]

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- The following statement will compile when placed in a main method: ---------------------------- Chimchar chimp = new Pokemon(); A) True B) False

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- The following statement will compile when placed in a main method: ---------------------------- Chimchar chimp = new Pokemon(); B) False

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- The following statement will compile when placed in a main method: ---------------------------- Pokemon chimchar = new Pokemon(); A) True B) False

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- The following statement will compile when placed in a main method: ---------------------------- Pokemon chimchar = new Pokemon(); B) False

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- The following statement will compile when placed in a main method: ---------------------------- Pokemon pokemon = new Chimchar(); A) True B) False

Review the following to answer the question below: ---------------------------- public abstract class Pokemon { public abstract Pokemon evolve(); public String toString() { return "Pokemon[?]"; } } ---------------------------- public class Chimchar extends Pokemon { private String nickname; public Chimchar(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Chimchar"; } } @Override public Pokemon evolve() { return new Monferno(nickname); } @Override public String toString() { return "Chimchar[" + nickname + "]"; } } ---------------------------- public class Monferno extends Pokemon { private String nickname; public Monferno(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Monferno"; } } @Override public Pokemon evolve() { return new Infernape(nickname); } @Override public String toString() { return "Monferno[" + nickname + "]"; } } ---------------------------- public class Infernape extends Pokemon { private String nickname; public Infernape(String nickname) { if (!nickname.isBlank()) { this.nickname = nickname; } else { this.nickname = "Infernape"; } } @Override public Pokemon evolve() { return null; } @Override public String toString() { return "Infernape[" + nickname + "]"; } } ---------------------------- The following statement will compile when placed in a main method: ---------------------------- Pokemon pokemon = new Chimchar(); B) False

Review the following to answer the question below: ---------------------------- public class Foo { private int number; public Foo(int num) { number = num; } public int getNum() { return number; } } ---------------------------- public class Bar extends Foo { private int number; public Bar(int num) { super(num++); number = num; } } ---------------------------- public class FooBar extends Bar { private int number; public FooBar(int num) { super(num++); number = num; } } ---------------------------- Given the following statements, assuming this statement is in a correctly defined main method, what will the result be? ---------------------------- Foo footwo = new FooBar(7); System.out.println(footwo.getNum()); A) Runtime Error B) Compiletime Error C) 15 D) 7 E) 8

Review the following to answer the question below: ---------------------------- public class Foo { private int number; public Foo(int num) { number = num; } public int getNum() { return number; } } ---------------------------- public class Bar extends Foo { private int number; public Bar(int num) { super(num++); number = num; } } ---------------------------- public class FooBar extends Bar { private int number; public FooBar(int num) { super(num++); number = num; } } ---------------------------- Given the following statements, assuming this statement is in a correctly defined main method, what will the result be? ---------------------------- Foo footwo = new FooBar(7); System.out.println(footwo.getNum()); D) 7

Review the following to answer the question below: ---------------------------- public class Foo { private int number; public Foo(int num) { number = num; } public int getNum() { return number; } } ---------------------------- public class Bar extends Foo { private int number; public Bar(int num) { super(num++); number = num; } } ---------------------------- public class FooBar extends Bar { private int number; public FooBar(int num) { super(num++); number = num; } } ---------------------------- Which of the following is not a valid polymorphic statement in the Java Programming Language? A) FooBar barfoo = new Bar(7); B) Bar bar = new FooBar(5); C) FooBar foobar = new FooBar(9); D) Foo oof = new FooBar(12); E) Foo foo = new Bar(7);

Review the following to answer the question below: ---------------------------- public class Foo { private int number; public Foo(int num) { number = num; } public int getNum() { return number; } } ---------------------------- public class Bar extends Foo { private int number; public Bar(int num) { super(num++); number = num; } } ---------------------------- public class FooBar extends Bar { private int number; public FooBar(int num) { super(num++); number = num; } } ---------------------------- Which of the following is not a valid polymorphic statement in the Java Programming Language? A) FooBar barfoo = new Bar(7);

Review the following to answer the question below: ---------------------------- public static void main(String[] args) { LinkedList<Integer> sll = new LinkedList<>(); sll.push(5); sll.push(7); sll.push(9); sll.push(10); sll.push(11); sll.push(15); sll.push(19); sll.pop(); sll.pop(); System.out.println(sll.peek()); printLinkedList(sll); } private static void printLinkedList(LinkedList<Integer> list) { int length = list.size(); for (int i = 0; i < length; i++) { System.out.print(list.get(i)); if (i != length - 1) { System.out.print(" -> "); } } } ---------------------------- What will be the result of the second print statement in the program? A) 5 -> 7 -> 9 -> 10 -> 11 -> 19 B) 9 -> 10 -> 11 -> 15 -> 19 C) 5 -> 7 -> 9 -> 10 -> 11 D) 11 -> 10 -> 9 -> 7 -> 5 E) None of the options are valid.

Review the following to answer the question below: ---------------------------- public static void main(String[] args) { LinkedList<Integer> sll = new LinkedList<>(); sll.push(5); sll.push(7); sll.push(9); sll.push(10); sll.push(11); sll.push(15); sll.push(19); sll.pop(); sll.pop(); System.out.println(sll.peek()); printLinkedList(sll); } private static void printLinkedList(LinkedList<Integer> list) { int length = list.size(); for (int i = 0; i < length; i++) { System.out.print(list.get(i)); if (i != length - 1) { System.out.print(" -> "); } } } ---------------------------- What will be the result of the second print statement in the program? D) 11 -> 10 -> 9 -> 7 -> 5

Review the following to answer the question below: ----------------------------- public static void main(String[] args) { LinkedList<Integer> sll = new LinkedList<>(); sll.push(5); sll.push(7); sll.push(9); sll.push(10); sll.push(11); sll.push(15); sll.push(19); sll.pop(); sll.pop(); System.out.println(sll.peek()); printLinkedList(sll); } private static void printLinkedList(LinkedList<Integer> list) { int length = list.size(); for (int i = 0; i < length; i++) { System.out.print(list.get(i)); if (i != length - 1) { System.out.print(" -> "); } } } ----------------------------- What will be the result of the first print statement in the program? A) 19 B) 11 C) 15 D) 5 E) 7

Review the following to answer the question below: ----------------------------- public static void main(String[] args) { LinkedList<Integer> sll = new LinkedList<>(); sll.push(5); sll.push(7); sll.push(9); sll.push(10); sll.push(11); sll.push(15); sll.push(19); sll.pop(); sll.pop(); System.out.println(sll.peek()); printLinkedList(sll); } private static void printLinkedList(LinkedList<Integer> list) { int length = list.size(); for (int i = 0; i < length; i++) { System.out.print(list.get(i)); if (i != length - 1) { System.out.print(" -> "); } } } ----------------------------- What will be the result of the first print statement in the program? B) 11

The following is legal in Java because... ---------------------------- private void incrementByValue(int num) { //some rather interesting code here... } private void incrementByValue(double num) { //some rather interesting code here... } A) The above is legal in Java because of method replacement. B) The above is legal in Java because of method overloading. C) The above is legal in Java because of method separation. D) The above is legal in Java because of method overriding. E) The above is not legal in Java.

The following is legal in Java because... ---------------------------- private void incrementByValue(int num) { //some rather interesting code here... } private void incrementByValue(double num) { //some rather interesting code here... } B) The above is legal in Java because of method overloading.

The following loop will never terminate. ---------------------------- for(int i = 0; i < 10; i--) { // Do something } A) True B) False

The following loop will never terminate. ---------------------------- for(int i = 0; i < 10; i--) { // Do something } B) False

The following statement is valid in Java: ---------------------------- HashMap<Integer, String> hashmap = new HashMap<>(); A) True B) False

The following statement is valid in Java: ---------------------------- HashMap<Integer, String> hashmap = new HashMap<>(); A) True

The following statement is valid in Java: ---------------------------- LinkedList<double> linkedList = new LinkedList<>(); A) True B) False

The following statement is valid in Java: ---------------------------- LinkedList<double> linkedList = new LinkedList<>(); B) False

What are the parameters of the method? ----------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } a) int[] arr1, int[] arr2 b) int[] c) int[][] d) There are no parameters for the method. e) None of the above

What are the parameters of the method? ----------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } a) int[] arr1, int[] arr2

What are the values of a, b and c after the execution of the following code fragment? ---------------------------- int a, b; int c = 7; a = c++; b = ++a + c--; A) 9, 15, 8 B) 8, 16, 8 C) 8, 16, 7 D) 8, 15, 8 E) 9, 16, 7

What are the values of a, b and c after the execution of the following code fragment? ---------------------------- int a, b; int c = 7; a = c++; b = ++a + c--; C) 8, 16, 7

What class do all classes extend? A) All of the options are valid. B) Class C) Enum D) Object E) None of the options are valid.

What class do all classes extend? D) Object

What does the following statement evaluate to? ---------------------------- true != false != true A) True B) False

What does the following statement evaluate to? ---------------------------- true != false != true B) False

What does this main method print on execution? ---------------------------- public static void main(String[] args) { int[] a = {3, 1, 2, 4, 0}; int[] b = a; for (int i = 0; i < a.length; i++) { a[i] = a[(a[i] + 3) % a.length]; } System.out.println(b[1]); } A) 3 B) ArrayIndexOutOfBoundsException C) 0 D) 1 E) 2

What does this main method print on execution? ---------------------------- public static void main(String[] args) { int[] a = {3, 1, 2, 4, 0}; int[] b = a; for (int i = 0; i < a.length; i++) { a[i] = a[(a[i] + 3) % a.length]; } System.out.println(b[1]); } C) 0

What exception needs to be caught when using the method sleep() from a Thread object? A) UnsignedTimeSignatureException B) ExtendedTimeImplicationException C) InterruptedException D) NullPointerException E) WaitingException

What exception needs to be caught when using the method sleep() from a Thread object? C) InterruptedException

What interface must you first implement before serializing an object? A) Serializable B) Splitable C) Comparable D) Seriable E) Streamable

What interface must you first implement before serializing an object? A) Serializable

What is a class? A) an object B) a singleton C) a data structure D) an enumeration E) a blueprint for an object

What is a class? E) a blueprint for an object

What is the accessibility modifier of the method? ---------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } A) public B) package-private C) private D) int[][] E) static

What is the accessibility modifier of the method? ---------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } B) package-private

What is the binary equivalent of 53? A) 0100 0010 B) 0011 0001 C) 0011 0101 D) 0001 1111 E) 0011 0111

What is the binary equivalent of 53? C) 0011 0101

What is the output after printing the variable num? ---------------------------- double num = 3 / 4; A) 0.0 B) 1 C) 1.0 D) 0 E) 0.75

What is the output after printing the variable num? ---------------------------- double num = 3 / 4; A) 0.0

What is the output of the following block of code? ----------------------------- public void Foo() { int number = 10; int secondNumber = 20; System.out.print(++number + " "); System.out.print(number++ + " "); System.out.print(secondNumber-- + " "); System.out.print(--secondNumber + " "); number -= secondNumber; System.out.print(number++); } A) 11 10 19 17 -5 B) 10 11 18 20 -7 C) 11 11 20 18 -6 D) 11 11 20 17 -7 E) None of the options are valid.

What is the output of the following block of code? ----------------------------- public void Foo() { int number = 10; int secondNumber = 20; System.out.print(++number + " "); System.out.print(number++ + " "); System.out.print(secondNumber-- + " "); System.out.print(--secondNumber + " "); number -= secondNumber; System.out.print(number++); } C) 11 11 20 18 -6

What is the output of the following program? ---------------------------- public class Swapper { public static void swap(int a, int b) { int temp = a; a = b; b = temp; } public static void main(String[] args) { int a = 5; int b = 7; swap(a, b); System.out.print(a + "," + b); } } A) 7,7 B) 7,5 C) None of the options are valid. D) 5,5 E) 5,7

What is the output of the following program? ---------------------------- public class Swapper { public static void swap(int a, int b) { int temp = a; a = b; b = temp; } public static void main(String[] args) { int a = 5; int b = 7; swap(a, b); System.out.print(a + "," + b); } } E) 5,7

What is the return type of the method? ---------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } a) void b) int[] c) There is no return type for the method. d) int[][] e) static

What is the return type of the method? ---------------------------- static int[][] makeMatrix(int[] arr1, int[] arr2) throws ArrayIndexOutOfBoundsException { //some rather interesting code goes here... } d) int[][]

What is the two's complement representation of -43 using an 8-bit word? A) 1101 0101 B) 1101 0111 C) 1100 0110 D) 1101 0100 E) 1100 0101

What is the two's complement representation of -43 using an 8-bit word? A) 1101 0101

What is the value of this expression? ---------------------------- Integer.MAX_VALUE + 1 == Integer.MIN_VALUE A) True B) False

What is the value of this expression? ---------------------------- Integer.MAX_VALUE + 1 == Integer.MIN_VALUE A) True

What is the value stored in the variable j after executing the following statement? ---------------------------- int j = (15 | x) & 14; ---------------------------- In the aforementioned statement x is a variable of type int containing an integer between 0 (inclusive) and 15 (inclusive). A) 15 B) 16 C) 14 D) 0 E) 1

What is the value stored in the variable j after executing the following statement? ---------------------------- int j = (15 | x) & 14; ---------------------------- In the aforementioned statement x is a variable of type int containing an integer between 0 (inclusive) and 15 (inclusive). C) 14

What value will be returned by calling toTernaryString(34)? ---------------------------- public String toTernaryString(int decimal) { String result = ""; while (decimal > 0) { int remainder = decimal % 3; decimal /= 3; result = remainder + result; } return result; } A) 1101 B) 201 C) 1021 D) 221 E) 1001

What value will be returned by calling toTernaryString(34)? ---------------------------- public String toTernaryString(int decimal) { String result = ""; while (decimal > 0) { int remainder = decimal % 3; decimal /= 3; result = remainder + result; } return result; } C) 1021

What will be the output of the following program? ---------------------------- final class Test { public static void main(String[] args) { String name = "CS180"; name.concat(" Spring 2020"); System.out.printf("%s", name); } } A) Spring 2020 B) CS180 Spring 2020 C) An empty String D) CS180 E) This program does not compile.

What will be the output of the following program? ---------------------------- final class Test { public static void main(String[] args) { String name = "CS180"; name.concat(" Spring 2020"); System.out.printf("%s", name); } } D) CS180

What will be the output of the following program? ---------------------------- public class Question { public static void main(String[] args) { double result = 1 / 0; System.out.println(result); } } A) 0.0 B) Runtime error C) 0 D) 1 E) Compile time error

What will be the output of the following program? ---------------------------- public class Question { public static void main(String[] args) { double result = 1 / 0; System.out.println(result); } } B) Runtime error

What will the following block of code print? ----------------------------- public void printMatrix() { for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { System.out.print(i); } System.out.println(); } } A) 000 111 222 333 444 B) 111 222 333 444 555 C) 444 333 222 1111 D) 123 123 123 123 123 E) None of the options are valid.

What will the following block of code print? ----------------------------- public void printMatrix() { for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { System.out.print(i); } System.out.println(); } } A) 000 111 222 333 444

Which of the following assertions about method overriding is true? A) A method can be overridden only in the same class where the original method is defined B) Overriding is the same as overloading C) The signature of the overridden method must be different from the signature of the original method D) A derived class can override a method of the base class E) None of the assertions are true

Which of the following assertions about method overriding is true? D) A derived class can override a method of the base class

Which of the following constructs will always be executed at least once? A) switch B) do-while C) if D) for E) while

Which of the following constructs will always be executed at least once? B) do-while

Which of the following is NOT a type of loop in Java? A) for B) forever C) do-while D) All of the options can be used to create a loop in Java. E) while

Which of the following is NOT a type of loop in Java? B) forever

Which of the following is NOT considered a primitive type in the Java Programming Language? I) boolean II) Double III) Boolean IV) double V) Character A) I only B) I and IV C) All of the options are valid. D) II, III, and V E) None of the options are valid.

Which of the following is NOT considered a primitive type in the Java Programming Language? I) boolean II) Double III) Boolean IV) double V) Character D) II, III, and V

Which of the following is the default accessibility modifier of a method? A) private B) final C) package-private D) static E) public

Which of the following is the default accessibility modifier of a method? C) package-private

Which of the following statements best describe(s) encapsulation? I) It involves hiding implementation details from other programmers II) It allows us to inform other programmers about the implementation details of a class. III) It prevents other programmers from modifying certain fields or calling certain methods. A) I and II B) I and III C) I, II and III D) II only E) None of the options are valid.

Which of the following statements best describe(s) encapsulation? I) It involves hiding implementation details from other programmers II) It allows us to inform other programmers about the implementation details of a class. III) It prevents other programmers from modifying certain fields or calling certain methods. B) I and III

An algorithm must be "complete". What does that mean? A. It must give the right answer(s). B. It must handle anything that comes up. C. It must end, i.e., not run forever. D. It must be understandable to the person who or machine that is going to execute it. E. It must be written in a programming language.

[August 22 - Quiz 1] B. It must handle anything that comes up. --> This means that it is complete. ----------------------------- A. It must give the right answer(s). --> This means that it is correct. [B. CORRECT] C. It must end, i.e., not run forever. --> This means that it will end. D. It must be understandable to the person who or machine that is going to execute it. --> This is true, but not what "complete" means. E. It must be written in a programming language. --> Not necessary. Algorithms are stated in lots of languages.

In class Robot is a method that begins... ----------------------------- public static void main(String[] args) { ----------------------------- Which best describes method main()? A. Method main() is where program execution begins. B. Method main() is the Constructor method of class Robot. C. Method main() must be the only method in class Robot. D. Method main() must be where all input/output is done. E. Method main() must be the first method at the top of class Robot.

[August 24 - Quiz 2] A. Method main() is where program execution begins. --> Without a main method, your class is not a program. ----------------------------- [A. CORRECT] B. Method main() is the Constructor method of class Robot. --> That would be named Robot (the name of the class). C. Method main() must be the only method in class Robot. --> There can be lots of methods in class Robot. D. Method main() must be where all input/output is done. --> Input/output can be done in any methods in class Robot. E. Method main() must be the first method at the top of class Robot. --> The main method can be anywhere in the set of methods.

After which line of code do you not need to consume the Newline character before continuing to take input? A. String country = scanner.nextLine(); B. float average = scanner.nextFloat(); C. boolean status = scanner.nextBoolean(); D. int num = scanner.nextInt(); E. None of the other choices are correct.

[August 26 - Quiz 3] A. String country = scanner.nextLine(); --> the nextInt(), nextBoolean(), and nextFloat() methods of the Scanner class do not consume the Newline character, while the nextLine() method already does.Therefore, in the case of option A), we wouldn't have a Newline character in the pipeline that is yet to be consumed, and can continue to take input. ----------------------------- [A. CORRECT] B. float average = scanner.nextFloat(); C. boolean status = scanner.nextBoolean(); D. int num = scanner.nextInt(); E. None of the other choices are correct.

----------------------------- String school = new String ("purdue"); ----------------------------- To what string does school point after the statement...? ----------------------------- String s3 = school.toUpperCase(); ----------------------------- A. "purduePURDUE" B. "PURDUE purdue" C. "Purdue" D. "PURDUE" E. "purdue"

[August 29 - Quiz 4] E. "purdue" --> Remember that school.toUpperCase() does NOT change the string that school points to. It produces a new string "PURDUE", which s3 now points to. The variable school still points to the string "purdue". ----------------------------- A. "purduePURDUE" B. "PURDUE purdue" C. "Purdue" D. "PURDUE" [E. CORRECT]

What value does this expression return? ----------------------------- (double) (1/2) * 8 ----------------------------- A. 4.0 B. 4 C. 0.0 D. 0 E. 0.0625

[August 31 - Quiz 5] C. 0.0 --> Remember that what is in parentheses will be done first.(1/2) is integer division and (because of truncation) is 0. The (double) cast will change that to 0.0 To multiply 0.0 and 8, the 8 must be promoted to 8.0. And, of course, 0.0 * 8.0 is 0.0. ----------------------------- A. 4.0 B. 4 [C. CORRECT] D. 0 E. 0.0625

Stack or queue: What is the best data structure (and why) for keeping threads waiting to get a core (CPU) to run? A. A queue so that eventually each thread will move from back to front and get a core. B. A queue so that the run-time system can "peek" to see which thread will next be run. C. A stack so that a thread can be popped off and quickly moved to a core. D. A stack so that the most recent thread that was running can run again soon. E. A stack since it can hold more threads than a queue.

[November 14 - Quiz 34] A. A queue so that eventually each thread will move from back to front and get a core. --> We want threads to get a fair chance at running. ----------------------------- [A. CORRECT] B. A queue so that the run-time system can "peek" to see which thread will next be run. --> There is never any reason to "peek". C. A stack so that a thread can be popped off and quickly moved to a core. --> A stack is a terrible idea, since a thread could get pushed down and never get out. D. A stack so that the most recent thread that was running can run again soon. --> A stack is a terrible idea. E. A stack since it can hold more threads than a queue. --> A stack is a terrible idea.

Which is correct about a HashMap<K,V> variable named map? A. Either K or V could be a primitive type. B. map[K] = V; is the way to put a value in the data structure. C. V = map[K]; is the way to get a value from the data structure. D. K is like an array subscript and V is like the value at that subscript location. E. V must be a reference type, but K can be a primitive type.

[November 16 - Quiz 35] D. K is like an array subscript and V is like the value at that subscript location. ----------------------------- A. Either K or V could be a primitive type. --> Both must be reference types (classes). B. map[K] = V; is the way to put a value in the data structure. --> No. map.put(K,V); C. V = map[K]; is the way to get a value from the data structure. --> No. V=map.get(K); [D. CORRECT] E. V must be a reference type, but K can be a primitive type. --> Both must be reference types (classes).

Where is the best place to run the JFrame? A. on the Event Dispatch thread B. on the main program thread C. on the SwingUtilities thread D. on the ActionListener interface E. anywhere is fine

[November 2 - Quiz 29] A. on the Event Dispatch thread --> This is the best place! ----------------------------- [A. CORRECT] B. on the main program thread --> This could cause the JFrame to freeze occasionally. C. on the SwingUtilities thread --> SwingUtilities is a class, not a thread. D. on the ActionListener interface --> The ActionListener interface reports if a button has been pushed. It is not a thread. E. anywhere is fine --> Event Dispatch thread is the best place!

When should you use recursion? A. When the solution requires more than 50 lines of code. B. When the solution requires method A calling method B and method B calling method C. C. When the solution is going to take one loop. D. When the solution is going to take a loop inside a loop. E. When the solution is going to take a lot of loops or you cannot determine how many loops you will need.

[November 28 - Quiz 36] E. When the solution is going to take a lot of loops or you cannot determine how many loops you will need. ----------------------------- A. When the solution requires more than 50 lines of code. --> Number of lines of code not important. B. When the solution requires method A calling method B and method B calling method C. --> This is NOT recursion. C. When the solution is going to take one loop. --> Perfect job for an iterative solution. D. When the solution is going to take a loop inside a loop. --> Still a good job for an iterative solution. [E. CORRECT]

Which one of the statements about Java GUIs is true? A. The BorderLayout add method always requires two parameters (component, location). B. You can change the JFrame's layout manager to be GridLayout. C. Using the GridLayout manager always requires that you specify exactly how many rows and columns to use. D. If a JFrame has a JPanel using the default FlowLayout manager that is showing 3 components per row and the user makes the JFrame much larger, the components will get larger and there will still be 3 components per row. E. Putting a JPanel inside a JPanel is not allowed.

[November 4 - Quiz 30] B. You can change the JFrame's layout manager to be GridLayout. --> See the slide "Changing the JFrame's LayoutManager" -- slide 61 for how to do that. ----------------------------- A. The BorderLayout add method always requires two parameters (component, location). --> There is an overloaded version with only one parameter that adds to BorderLayout.CENTER. [B. CORRECT] C. Using the GridLayout manager always requires that you specify exactly how many rows and columns to use. --> No. setLayout(new GridLayout(0,4)); says "four columns per row, as many rows as it takes". D. If a JFrame has a JPanel using the default FlowLayout manager that is showing 3 components per row and the user makes the JFrame much larger, the components will get larger and there will still be 3 components per row. --> No. There will likely be more than 3 components per row. E. Putting a JPanel inside a JPanel is not allowed. --> No. We showed several examples of doing just that.

What is a difference between an abstract class and an interface? A. Fields in an interface are public final static (i.e., constants). Fields in an an abstract class can be private. B. A Java class must say that it "implements" an interface, but it must say that it "abstract extends" an abstract class. C. A Java class can extend multiple abstract classes, but can implement only one interface. D. An abstract class may have methods with method bodies. An interface may not have methods with method bodies. E. An abstract class must have fields. An interface is not required to have any fields.

[November 7 - Quiz 31] A. Fields in an interface are public final static (i.e., constants). Fields in an an abstract class can be private. ----------------------------- [A. CORRECT] B. A Java class must say that it "implements" an interface, but it must say that it "abstract extends" an abstract class. --> No. It just says that it "extends" an abstract class. C. A Java class can extend multiple abstract classes, but can implement only one interface. --> The other way around. A Java class can extend multiple interfaces, but can implement only one (abstract or concrete) class. D. An abstract class may have methods with method bodies. An interface may not have methods with method bodies. --> An interface may have default methods with method bodies. E. An abstract class must have fields. An interface is not required to have any fields. --> Neither is required to have fields.

Why in the MyArrayList class does the method reallocate() have a private access modifier? A. It must be private since it is called by the public method add(String). B. It is not to be run by someone who instantitates a MyArrayList object. C. It creates a new array which the variable strings is going to reference. D. So that it cannot be called by any other method in the MyArrayList class. E. It uses the private field strings.

[November 9 - Quiz 32] B. It is not to be run by someone who instantitates a MyArrayList object. --> A private method is hidden from someone who instantitates a MyArrayList object. ----------------------------- A. It must be private since it is called by the public method add(String). --> It is called by the public method add(String), but that is not why it is private. [B. CORRECT] C. It creates a new array which the variable strings is going to reference. --> It does create a new array which the variable strings is going to reference, but that is not why it is private. D. So that it cannot be called by any other method in the MyArrayList class. --> Private methods can be called by any other method (public or private) in a class. E. It uses the private field strings. --> It does use the private field strings, but that is not why it is private.

A class that implements an Interface must have... A. a default method B. methods with the same name as the methods declared in the Interface C. methods with the same signature as the methods declared in the Interface D. methods with the same signature and the same return type as the methods declared in the Interface E. methods with the same signature, same return type, and same parameter names as the methods declared in the Interface

[October 12 - Quiz 21] D. methods with the same signature and the same return type as the methods declared in the Interface ----------------------------- A. a default method --> Default methods are not required B. methods with the same name as the methods declared in the Interface --> see D C. methods with the same signature as the methods declared in the Interface --> see D [D. CORRECT] E. methods with the same signature, same return type, and same parameter names as the methods declared in the Interface --> Parameter names need not be the same

Which of these is an example of Overriding? A. Class Person has a method changeAddress() and Class Student (a subclass of Person) also has a method changeAddress() but with a different signature B. Class Person has a method changeAddress() and Class Student (a subclass of Person) also has a method changeAddress() with the same signature C. Class Student has a method changeAddress(), but its superclass Person does not have a method changeAddress() D. Class Person has a method changeAddress(), but its subclass Student does not have a method changeAddress() E. Class Student has three methods named changeAddress() all with different signatures

[October 14 - Quiz 22] B. Class Person has a method changeAddress() and Class Student (a subclass of Person) also has a method changeAddress() with the same signature --> Overriding is when there is a method with the same signature in a subclass ----------------------------- A. Class Person has a method changeAddress() and Class Student (a subclass of Person) also has a method changeAddress() but with a different signature --> This is an example of Overloading [B. CORRECT] C. Class Student has a method changeAddress(), but its superclass Person does not have a method changeAddress() --> Has nothing to do with Overriding D. Class Person has a method changeAddress(), but its subclass Student does not have a method changeAddress() --> Has nothing to do with Overriding E. Class Student has three methods named changeAddress() all with different signatures --> This is an example of Overloading

Suppose that a main method encounters the statement ----------------------------- t3.join(); ----------------------------- Suppose that thread t3's run() method has completed running. What happens? A. The main method waits for all running threads to complete their run() methods before proceeding B. The main method waits for any other thread to complete its run() method before proceeding C. The main method proceeds to the next statement following the t3.join(); statement D. Thread t3 is re-started E. All threads except t3 that are running are terminated

[October 17 - Quiz 23] C. The main method proceeds to the next statement following the t3.join(); statement ----------------------------- t3.join(); ----------------------------- means "wait here until t3 has completed running and then go on to the next statement". ----------------------------- A. The main method waits for all running threads to complete their run() methods before proceeding B. The main method waits for any other thread to complete its run() method before proceeding [C. CORRECT] D. Thread t3 is re-started E. All threads except t3 that are running are terminated

You are on a Software Engineering team. You are working on your part of the project and spending a lot of time. But, you have run into a problem and have been stuck for a couple of days. You can't get your software to work. What should you do? A. Look online and see if you can find some code that was written by someone else that you can use. B. You have a friend on another team who is writing the same code that you are. Ask her for a copy of her code. C. Make sure that your teammates know exactly what you have done and are doing. Explain any problems you have run into and ask for help. D. Don't tell your teammates that you are having problems. Wait until the day the project is due and tell them then if you can't get your software to work. E. Drop the course.

[October 19 - Quiz 24] C. Make sure that your teammates know exactly what you have done and are doing. Explain any problems you have run into and ask for help. ----------------------------- A. Look online and see if you can find some code that was written by someone else that you can use. --> You should NOT do this. This is a great example of cheating! B. You have a friend on another team who is writing the same code that you are. Ask her for a copy of her code. --> You should NOT do this, either. This is another great example of cheating! [C. CORRECT] D. Don't tell your teammates that you are having problems. Wait until the day the project is due and tell them then if you can't get your software to work. --> This would be a terrible way to treat your teammates. Don't wait until too late and then drop the bomb that you cannot get your part done on time. E. Drop the course. --> NO! Decide before you start Projects 4 and 5 that you are going to complete the class. If not, don't let us put you on a team!

Which of these statements about Sockets and ServerSockets is correct? A. A ServerSocket constructor specifies the IP address (or DNS name) and port number. B. Both clients and servers use both Sockets and ServerSockets. C. Both clients and servers use Sockets. A server uses a ServerSocket to wait for a client to appear. D. Servers use only ServerSockets and do not use Sockets. E. A Socket object invokes the accept() method to try to connect to a server.

[October 24 - Quiz 26] C. Both clients and servers use Sockets. A server uses a ServerSocket to wait for a client to appear. ----------------------------- A. A ServerSocket constructor specifies the IP address (or DNS name) and port number. --> A ServerSocket constructor specifies ONLY the port number. B. Both clients and servers use both Sockets and ServerSockets. --> Servers use both Sockets and ServerSockets. But, clients use only Sockets. [C. CORRECT] D. Servers use only ServerSockets and do not use Sockets. --> Servers use both Sockets and ServerSockets. E. A Socket object invokes the accept() method to try to connect to a server. --> Only ServerSocket objects use the accept() method.

int tryAgain = JOptionPane.showConfirmDialog(null, "Do you want to try again?", "Alert", JOptionPane.YES_NO_OPTION); ----------------------------- If you have the statement above in your program, which of the following is the best way to check if the user clicked the NO button? A. if (tryAgain == 0) B. if (tryAgain == -1) C. if (tryAgain == JOptionPane.YES_NO_OPTION) D. if (tryAgain == JOptionPane.NO_OPTION) E. if (JOptionPane.NO_OPTION == 0)

[October 26 - Quiz 27] D. if (tryAgain == JOptionPane.NO_OPTION) --> This is the named constant you use to see if the user clicked the NO button. ----------------------------- A. if (tryAgain == 0) --> If you want to compare the int that was returned, the NO button would be 1. B. if (tryAgain == -1) --> If you want to compare the int that was returned, the NO button would be 1. C. if (tryAgain == JOptionPane.YES_NO_OPTION) --> This is the named constant you use to say that you want two buttons -- YES and NO. [D. CORRECT] E. if (JOptionPane.NO_OPTION == 0) --> JOptionPane.NO_OPTION is the named constant for 1, indicating that the user clicked the NO button.

What is the primary benefit of using buffers for File I/O? A. The program runs faster. B. The program uses less memory. C. All input data is kept in the file until needed. D. All output data is immediately written to a file. E. The entire file is input at once.

[October 5 - Quiz 19] A. The program runs faster. --> Performing fewer physical reads and writes speeds up the program. ----------------------------- [A. CORRECT] B. The program uses less memory. --> No. Buffers make the program use more memory. C. All input data is kept in the file until needed. --> No. Some input data is read from the file before it is needed. D. All output data is immediately written to a file. --> No. Output data stays in the buffer and is only written when the output buffer is full (or flushed). E. The entire file is input at once. --> No. Only a portion of the file is input, just enough to fill the input buffer.

Which of the following follows from the rule "Catches must be ordered from the lowest subclass to the highest superclass"? A. There should be no catch handler for the Exception class after the try block. B. The catch handler for the StudentNotFoundException class should be after the catch handler for the Exception class. C. The catch handler for the StudentNotFoundException class should be before the catch handler for the NullPointerException class. D. The catch handler for the Exception class should be the last catch handler after the try block. E. The catch handler for the Exception class should be the first catch handler after the try block.

[October 7 - Quiz 20] D. The catch handler for the Exception class should be the last catch handler after the try block. --> The Exception class catch handler will work for any exceptions. Put it last! ----------------------------- A. There should be no catch handler for the Exception class after the try block. --> No. It is fine to have a catch handler for the Exception class. Just be sure to put it last. B. The catch handler for the StudentNotFoundException class should be after the catch handler for the Exception class. --> No. The Exception class catch handler will work for any exceptions. Don't put any catch handlers for other classes after it. C. The catch handler for the StudentNotFoundException class should be before the catch handler for the NullPointerException class. --> No. These have nothing to do with each other. The order of these two does not matter. [D. CORRECT] E. The catch handler for the Exception class should be the first catch handler after the try block. --> No. The Exception class catch handler will work for any exceptions. Don't put any catch handlers for other classes after it.

1. int x = 0; 2. System.out.println(x++); 3. System.out.println(++x); ----------------------------- What does this code display on screen? A. Prints 1, then 1 B. Prints 1, then 2 C. Prints 0, then 1 D. Prints 0, then 2 E. Prints 0, then 3

[September 12 - Quiz 10] D. Prints 0, then 2 --> In statement 1, x is given the initial value 0. In statement 2, x++ is a post-increment, meaning that the statement is executed as if the ++ were not there (printing 0) and then x is incremented, making it 1. In statement 3, ++x is a pre-increment, meaning that x is first incremented, making it 2 and then the statement is executed (printing 2). ----------------------------- A. Prints 1, then 1 B. Prints 1, then 2 C. Prints 0, then 1 [D. CORRECT] E. Prints 0, then 3

When should you use a do-while loop? A. When the loop is an indefinite loop. B. When the loop is a definite loop. C. When you want to use a sentinel boolean variable as the loop conditional. D. When the loop must be executed at least once. E. When the loop body could be executed zero times.

[September 14 - Quiz 11] D. When the loop must be executed at least once. ----------------------------- A. When the loop is an indefinite loop. --> Can use either a while or do-while for an indefinite loop. Usually a while loop is better. B. When the loop is a definite loop. --> Use a for-loop for a definite loop. C. When you want to use a sentinel boolean variable as the loop conditional. --> A do-while loop usually does NOT use a sentinel boolean variable. [D. CORRECT] E. When the loop body could be executed zero times. --> No. The body of a do-while loop is always executed at least once.

Which one of these is correct about return statements? A. All methods must have at least one return statement. B. A return statement must always be the last statement in a method. C. A method with a void return type cannot have a return statement. D. A method does not need a return statement if it is a method with a void return type, but it may have one or more. E. A method with an int return type may have some return statements that return ints and some that return nothing.

[September 19 - Quiz 13] D. A method does not need a return statement if it is a method with a void return type, but it may have one or more. --> In this case the return statements are used to leave the method from different points ... like early if something goes wrong. ----------------------------- A. All methods must have at least one return statement. --> No. See the correct answer D. B. A return statement must always be the last statement in a method. --> No. There can be more than one return statement and they can be anywhere in the method. C. A method with a void return type cannot have a return statement. --> No. See the correct answer D. [D. CORRECT] E. A method with an int return type may have some return statements that return ints and some that return nothing. --> No. Every return statement must return a value of the return type.

What are the resulting types used in this format: ----------------------------- %d, %d, %s, %f, %c. -----------------------------

[September 2 - Quiz 6] The correct answer is: int, int, String, double, char. ----------------------------- Remember that: %d is used to indicate a variable of type int %s is used for Strings %f is used for floating point numbers (include the double primitive type) %c is used for char

All of the following are used to determine the "signature" of a method except which one? A. return type B. method name C. number of parameters D. type of parameters E. order of parameters

[September 21 - Quiz 14] A. return type --> The signature of... ----------------------------- double calc (int x, double y)... ----------------------------- is a method named "calc" with two parameters -- an int followed by a double. The double return type is NOT part of the signature. ----------------------------- [A. CORRECT] B. method name C. number of parameters D. type of parameters E. order of parameters

The variable s is a String and the variable t is an array. Which of the following tell you how many characters are in the String s and how many storage locations are in the array t? A. s.length(), t.length() B. s.length, t.length C. s.length(), t.length D. s.length, t.length() E. s.length-1, t.length()

[September 26 - Quiz 16] C. s.length(), t.length To get the length of a String, you must run the length() method, as in s.length() To get the length of an array, you can use the array's instance variable length, as in t.length. ----------------------------- A. s.length(), t.length() B. s.length, t.length [C. CORRECT] D. s.length, t.length() E. s.length-1, t.length()

ArrayList<String> list1 = new ArrayList<String>(); //declares an ArrayList of Strings named list1. String[] list2 = new String[10]; //declares an array of Strings named list2. ----------------------------- Assume that both list1 and list2 contain the same five strings. Which statement below does the same thing as...? ----------------------------- list1.add(3,"Tricky"); ----------------------------- A. list2 = "Tricky"; B. list2[3] = "Tricky"; C. list2[4] = "Tricky"; D. list2.add(3,"Tricky"); E. None of the above.

[September 28 - Quiz 17] E. None of the above. In an ArrayList add(i,e) adds e at index i, pushing other values down. So, list1.add(3,"Tricky"); adds "Tricky" at index 3, pushing what had been at 3 to 4 and what had been at 4 to 5. The ArrayList now has six strings. The Java array has no add method or anything else that does this. ----------------------------- A. list2 = "Tricky"; --> No. list2 points to the beginning of an array, not a place where a string can be stored. B. list2[3] = "Tricky"; --> No. This just has index 3 point to "Tricky". The string that was there before is lost. C. list2[4] = "Tricky"; --> No. This just has index 4 point to "Tricky". The string that was there before is lost. D. list2.add(3,"Tricky"); --> No. The Java array has no add method. [E. CORRECT]

Which of the following always works to test if two string variables point to strings that say exactly the same thing? A. if (school.sameas(university)) B. if (school.equals.university) C. if (school.equals(university)) D. if (school == university) E. if (school = university)

[September 7 - Quiz 8] C. if (school.equals(university)) --> run the equals method for the school object comparing it to the university object ----------------------------- A. if (school.sameas(university)) --> Java has no sameas method that works for strings B. if (school.equals.university) --> equals is a method that needs a parameter in parentheses [C. CORRECT] D. if (school == university) --> This checks to see if the school variable and the university variable contain the same address. This only works some of the time ... not always. E. if (school = university) --> NO! The = operator is not a comparison operator

I n d i a n a p o l i s 0 1 2 3 4 5 6 7 8 9 10 11 s.length() = 12 ----------------------------- Suppose that s is a string variable pointing to the string "Indianapolis". Which of the following returns the substring "dianapol" ... that is, the original string with the first two and last two characters removed? A. s.substring (2,2) B. s.substring (3, s.length() - 1) C. s.substring (3, s.length() - 2) D. s.substring (2, s.length() - 1) E. s.substring (2, s.length() - 2)

[September 9 - Quiz 9] E. s.substring (2, s.length() - 2) --> [2,10) "dianapol" ----------------------------- A. s.substring (2,2) --> [2,2) compilation error, the end character 1 is before the begin character 2 B. s.substring (3, s.length() - 1) --> [3,11) "ianapoli" C. s.substring (3, s.length() - 2) --> [3,10) "ianapol" D. s.substring (2, s.length() - 1) --> [2,11) "dianapoli" [E. CORRECT]


Related study sets

Chapter 27: Growth and Development of the School-Aged Child

View Set

peptic ulcer disease practice questions

View Set

Chapter 8: Inventories: Measurement

View Set

A Day No Pigs Would Die Chapters 3-4

View Set

CIS 050 Microcomputer Applications SIMnet

View Set

Wongs nursing care of children Ch 23 Pediatric nursing interventions and skills

View Set

Ch 5 (pp.60-75) Supplement p.1-4

View Set