CSCI 2351: Object-Oriented Design - Ch. 11, 12, 13 Quizzes

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/116

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

117 Terms

1
New cards

parent class; general class


possible answers:

superclass

this

super

subclass

inheritance

extends

override

superclass

2
New cards

used to reference the calling object followed by the data field


possible answers:

superclass

this

super

subclass

inheritance

extends

override

this

3
New cards

used to invoke the superclass's methods and constructors


possible answers:

superclass

this

super

subclass

inheritance

extends

override

super

4
New cards

specialized class, child class; inherits accessible data fields and methods from its parent class and may also add new data fields and methods


possible answers:

superclass

this

super

subclass

inheritance

extends

override

subclass

5
New cards

enables you to define a general class (i.e., a superclass) and later extend it to more specialized classes (i.e., subclasses)


possible answers:

superclass

this

super

subclass

inheritance

extends

override

inheritance

6
New cards

keyword used to tell the compiler that a subclass belongs to a superclass


possible answers:

superclass

this

super

subclass

inheritance

extends

override

extends

7
New cards

a subclass modifies the implementation of a method defined in the superclass; must have the same signature as its superclass


possible answers:

superclass

this

super

subclass

inheritance

extends

override

override

8
New cards

Object-oriented programming allows you to derive new classes from existing classes. This is called ___.


a. abstraction

b. encapsulation

c. generalization

d. inheritance

d. inheritance

9
New cards

Which of the following statements are true? Select all that apply.

a. A subclass is a subset of a superclass.

b. "class A extends B" means A is a subclass of B.

c. A subclass is usually extended to contain more functions and more detailed information than its superclass.

d. "class A extends B" means B is a subclass of A.

b. "class A extends B" means A is a subclass of B.

c. A subclass is usually extended to contain more functions and more detailed information than its superclass.

10
New cards

Which of the following statements are true? Select all that apply.

a. The keyword this is used in an accessor/mutator method on a private data field within its own class

b. Private data fields must be accessed/mutated through public accessors/mutators if defined in the superclass

c. The keyword this is used for all private data fields.

d. Private data fields in a superclass can be used directly in a subclass.

e. The keyword this is not used in an accessor/mutator method on a private data field belonging to its superclass

a. The keyword this is used in an accessor/mutator method on a private data field within its own class

b. Private data fields must be accessed/mutated through public accessors/mutators if defined in the superclass

e. The keyword this is not used in an accessor/mutator method on a private data field belonging to its superclass

11
New cards

Suppose you create a class Square to be a subclass of GeometricObject. Analyze the following code:

Class Square extends GeometricObject {

double length;

Square(double length) {

GeometricObject(length);

}

}

a. The program has a compile error because you attempted to invoke the GeometricObject class's constructor illegally.

b. The program compiles fine, but it has a runtime error because of invoking the Square class's constructor illegally.

c. The program compiles fine, but you cannot create an instance of Square because the constructor does not specify the length of the Square.

a. The program has a compile error because you attempted to invoke the GeometricObject class's constructor illegally.

12
New cards

Which of the statements regarding the super keyword is incorrect?

a. You can use super to invoke a super class method.

b. You can use super.super.p to invoke a method in superclass's parent class.

c. You can use super to invoke a super class constructor.

d. You cannot invoke a method in superclass's parent class.

b. You can use super.super.p to invoke a method in superclass's parent class.

13
New cards

Analyze the following code:

public class Test {

public static void main(String[] args) {

B b = new B();

b.m(5);

System.out.println("i is " + b.i);

}

}

class A { int i;

public void m(int i) {

this.i = i;

}

}

class B extends A {

public void m(String s) {

}

}

a. The program has a compile error, because b.m(5) cannot be invoked since the method m(int) is hidden in B.

b. The program has a compile error, because m is overridden with a different signature in B.

c. The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

d. The program has a runtime error on b.i, because i is not accessible from b.

c. The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

14
New cards

a variable of a supertype can refer to a subtype object

possible answers:

polymorphism

override

overload

polymorphism

15
New cards

to provide a new implementation for a method in the subclass; the method must be the defined in the subclass using the same signature and the same or compatible return type

possible answers:

polymorphism

override

overload

override

16
New cards

to define multiple methods with the same name but different signatures

possible answers:

polymorphism

override

overload

overload

17
New cards

Analyze the following code:

public class Test {

public static void main(String[] args) {

new B();

}

}

class A {

int i = 7;

public A() {

System.out.println("i from A is " + i);

}

public void setI(int i) {

this.i = 2 * i;

}

}

class B extends A {

public B() {

setI(20);

// System.out.println("i from B is " + i);

}

@Override

public void setI(int i) {

this.i = 3 * i;

}

}

a. The constructor of class A is not called.

b. The constructor of class A is called and it displays "i from A is 60".

c. The constructor of class A is called and it displays "i from A is 7".

d. The constructor of class A is called and it displays "i from A is 40".

c. The constructor of class A is called and it displays "i from A is 7".

18
New cards

Analyze the following code:

public class Test {

public static void main(String[] args) {

new B();

}

}

class A {

int i = 7;

public A() {

setI(20);

System.out.println("i from A is " + i);

}

public void setI(int i) {

this.i = 2 * i;

}

}

class B extends A {

public B() {

// System.out.println("i from B is " + i);

}

@Override

public void setI(int i) {

this.i = 3 * i;

}

}

a. The constructor of class A is called and it displays "i from A is 40".

b. The constructor of class A is not called.

c. The constructor of class A is called and it displays "i from A is 7".

d. The constructor of class A is called and it displays "i from A is 60".

d. The constructor of class A is called and it displays "i from A is 60".

19
New cards

Which of the following statements are true? Select all that apply.

a. It is a compile error if two methods differ only in return type in the same class.

b. Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them.

c. A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden.

d. To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass.

e. A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated.

a. It is a compile error if two methods differ only in return type in the same class.

b. Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them.

c. A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden.

d. To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass.

e. A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated.

20
New cards

Which of the following statements are true? Select all that apply.

a. A method in a subclass can overload a method in the superclass.

b. A method can be overloaded in the same class.

c. If a method overrides another method, these two methods must have the same signature.

d. A method can be overridden in the same class.

e. If a method overloads another method, these two methods must have the same signature.

a. A method in a subclass can overload a method in the superclass.

b. A method can be overloaded in the same class.

c. If a method overrides another method, these two methods must have the same signature.

21
New cards

You can assign ___ to a variable of Object[] type. Select all that apply.

a. new char[100]

b. new java.util.Date[100]

c. new int[100]

d. new double[100]

e. new String[100]

b. new java.util.Date[100]

e. new String[100]

22
New cards

Given two reference variables t1 and t2, if t1 == t2 is true, t1.equals(t2) must be ___.

a. true

b. false

a. true

23
New cards

Given two reference variables t1 and t2, if t1.equals(t2) is true, t1 == t2 ___.

a. may be true or false

b. is always true

c. is always false

a. may be true or false

24
New cards

What is the output of the following code:

public class Test {

public static void main(String[] args) {

Object o1 = new Object();

Object o2 = new Object();

System.out.print((o1 == o2) + " " + (o1.equals(o2)));

}

}

a. false true

b. true false

c. true true

d. false false

d. false false

25
New cards

What is the output of the following code:

public class Test {

public static void main(String[] args) {

String s1 = new String("Java");

String s2 = new String("Java");

System.out.print((s1 == s2) + " " + (s1.equals(s2)));

}

}

a. false true

b. true false

c. true true

d. false false

a. false true

26
New cards

You can create an ArrayList using ___.

a. ArrayList()

b. new ArrayList[100]

c. new ArrayList<>()

d. new ArrayList[]

c. new ArrayList<>()

27
New cards

Invoking ___ removes all elements in an ArrayList x.

a. x.empty()

b. x.clean()

c. x.clear()

d. x.delete()

e. x.remove()

c. x.clear()

28
New cards

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing, Chicago, Singapore]?

a. x.add("Chicago")

b. x.add(0, "Chicago")

c. x.add(2, "Chicago")

d. x.add(1, "Chicago")

d. x.add(1, "Chicago")

29
New cards

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following method will cause the list to become [Beijing]? Select all that apply.

a. x.remove(2)

b. x.remove(1)

c. x.remove(0)

d. x.remove("Singapore")

b. x.remove(1)

d. x.remove("Singapore")

30
New cards

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following method will cause runtime errors? Select all that apply.

a. x.size()

b. x.set(2, "New York");

c. x.get(1)

d. x.get(2)

e. x.remove(2)

b. x.set(2, "New York");

d. x.get(2)

e. x.remove(2)

31
New cards

Invoking ___ returns the first element in an ArrayList x.

a. x.first()

b. x.get(0)

c. x.get()

d. x.get(1)

b. x.get(0)

32
New cards

Invoking ___returns the number of the elements in an ArrayList x.

a. x.getLength(0)

b. x.length(1)

c. x.size()

d. x.getSize()

c. x.size()

33
New cards

Analyze the following code. Select all that apply.

ArrayList list = new ArrayList();

list.add("Beijing");

list.add("Tokyo");

list.add("Shanghai");

list.set(3, "Hong Kong");

a. If you replace the last line by list.add(4, "Hong Kong"), the code will compile and run fine.

b. If you replace the last line by list.add(3, "Hong Kong"), the code will compile and run fine.

c. The last line in the code causes a runtime error because there is no element at index 3 in the array list.

d. The last line in the code has a compile error because there is no element at index 3 in the array list.

b. If you replace the last line by list.add(3, "Hong Kong"), the code will compile and run fine.

c. The last line in the code causes a runtime error because there is no element at index 3 in the array list.

34
New cards

What is the output of the following code?

ArrayList list = new ArrayList();

String s1 = new String("Java");

String s2 = new String("Java");

list.add(s1);

list.add(s2);

System.out.println((list.get(0) == list.get(1)) + " " + (list.get(0)).equals(list.get(1)));

a. true false

b. true true

c. false true

d. false false

c. false true

35
New cards

The output from the following code is ___.

java.util.ArrayList list = new java.util.ArrayList();

list.add("New York");

java.util.ArrayList list1 = list;

list.add("Atlanta");

list1.add("Dallas");

System.out.println(list1);

a. [New York, Atlanta]

b. [New York]

c. [New York, Atlanta, Dallas]

d. [New York, Dallas]

c. [New York, Atlanta, Dallas]

36
New cards

Suppose an ArrayList list contains {"red", "green", "red", "green"}. What is the list after the following code?

list.remove("red");

a. {"green", "red", "green"}

b. {"green", "green"}

c. {"red", "green", "green"}

d. {"red", "green", "red", "green"}

a. {"green", "red", "green"}

37
New cards

Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code?

String element = "red";

for (int i = 0; i < list.size(); i++)

if (list.get(i).equals(element))

list.remove(element);

a. {"green"}

b. {"red", "green"}

c. {}

d. {"red", "red", "green"}

b. {"red", "green"}

38
New cards

Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code?

String element = "red";

for (int i = 0; i < list.size(); i++)

if (list.get(i).equals(element)) {

list.remove(element);

i--;

}

a. {"red", "green"}

b. {"green"}

c. {}

d. {"red", "red", "green"}

b. {"green"}

39
New cards

Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code?

String element = "red";

for (int i = list.size() - 1; i >= 0; i--)

if (list.get(i).equals(element))

list.remove(element);

a. {"red", "red", "green"}

b. {"green"}

c. {}

d. {"red", "green"}

b. {"green"}

40
New cards

Show the output of the following code:

String[] array = {"red", "green", "blue"};

ArrayList list = new ArrayList<>(Arrays.asList(array));

list.add(0, "red");

System.out.println(list);

a. ["red", "red", "green", "blue"]

b. ["red", "green", "blue", "red"]

c. ["red", "green", "blue"]

d. ["red", "green", "red", "blue"]

a. ["red", "red", "green", "blue"]

41
New cards

Analyze the following code:

Double[] array = {1, 2, 3};

ArrayList list = new ArrayList<>(Arrays.asList(array));

System.out.println(list);

a. The code has a compile error because an integer such as 1 is automatically converted into an Integer object, but the array element type is Double.

b. The code is correct and displays [1, 2, 3].

c. The code is correct and displays [1.0, 2.0, 3.0].

d. The code has a compile error because asList(array) requires that the array elements are objects.

a. The code has a compile error because an integer such as 1 is automatically converted into an Integer object, but the array element type is Double.

42
New cards

Analyze the following code:

double[] array = {1, 2, 3};

ArrayList list = new ArrayList<>(Arrays.asList(array));

System.out.println(list);

a. The code has a compile error because asList(array) requires that the array elements are objects.

b. The code is correct and displays [1, 2, 3].

c. The code has a compile error because an integer such as 1 is automatically converted into an Integer object, but the array element type is Double.

d. The code is correct and displays [1.0, 2.0, 3.0].

a. The code has a compile error because asList(array) requires that the array elements are objects.

43
New cards

Analyze the following code:

double[] c = {1, 2, 3};

System.out.println(javA.util.Collections.max(c));

a. The code is correct and displays 3.

b. The code has a compile error on Integer[] c = {1, 2, 3}.

c. The code has a compile error on Collections.max(c). c cannot be an array.

d. The code is correct and displays 3.0.

c. The code has a compile error on Collections.max(c). c cannot be an array.

44
New cards

thrown by the JVM. There is little that the programmer can do other than notify the user and terminate


possible answers:

system error

throw

try

runtime error

catch

exception

finally clause

system error

45
New cards

executes an exception


possible answers:

system error

throw

try

runtime error

catch

exception

finally clause

throw

46
New cards

contains the code that is executed normally


possible answers:

system error

throw

try

runtime error

catch

exception

finally clause

try

47
New cards

errors that cause a problem to terminate abnormally


possible answers:

system error

throw

try

runtime error

catch

exception

finally clause

runtime error

48
New cards

handles the exception


possible answers:

system error

throw

try

runtime error

catch

exception

finally clause

catch

49
New cards

an object that represents an error or a condition that prevents execution from proceeding normally


possible answers:

system error

throw

try

runtime error

catch

exception

finally clause

exception

50
New cards

always executed regardless of whether an exception occurs or is caught


possible answers:

system error

throw

try

runtime error

catch

exception

finally clause

finally clause

51
New cards

Dividing an integer by zero, but not floating-point errors


possible answers:

ArithmeticException

IndexOutOfBoundsException

NullPointerException

VirtualMachineError

IllegalArgumentException

ClassNotFoundException

LinkageError

ArithmeticException

52
New cards

Index to an array is out of range


possible answers:

ArithmeticException

IndexOutOfBoundsException

NullPointerException

VirtualMachineError

IllegalArgumentException

ClassNotFoundException

LinkageError

IndexOutOfBoundsException

53
New cards

Attempt to access an object through a null reference variable


possible answers:

ArithmeticException

IndexOutOfBoundsException

NullPointerException

VirtualMachineError

IllegalArgumentException

ClassNotFoundException

LinkageError

NullPointerException

54
New cards

The JVM is broken or has run out of the resources it needs in order to continue operating


possible answers:

ArithmeticException

IndexOutOfBoundsException

NullPointerException

VirtualMachineError

IllegalArgumentException

ClassNotFoundException

LinkageError

VirtualMachineError

55
New cards

A method is passed an argument that is illegal or inappropriate


possible answers:

ArithmeticException

IndexOutOfBoundsException

NullPointerException

VirtualMachineError

IllegalArgumentException

ClassNotFoundException

LinkageError

IllegalArgumentException

56
New cards

Attempt to use a class that does not exist. If you try to run a nonexistent class using the java command or if your program were composed of, say, three class files, only two of which could be found


possible answers:

ArithmeticException

IndexOutOfBoundsException

NullPointerException

VirtualMachineError

IllegalArgumentException

ClassNotFoundException

LinkageError

ClassNotFoundException

57
New cards

A class has some dependency on another class, but the latter class has changed incompatibly after the compilation of the former class


possible answers:

ArithmeticException

IndexOutOfBoundsException

NullPointerException

VirtualMachineError

IllegalArgumentException

ClassNotFoundException

LinkageError

LinkageError

58
New cards

A Java exception is an instance of ___.

a. Throwable

b. Error

c. Exception

d. RuntimeException

e. NumberFormatException

a. Throwable

59
New cards

An instance of ___ describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully.

a. Exception

b. RuntimeException

c. NumberFormatException

d. Error

e. Throwable

d. Error

60
New cards

An instance of ___ describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program.

a. Exception

b. RuntimeException

c. NumberFormatException

d. Throwable

e. Error

a. Exception

61
New cards

An instance of ___ describes programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors.

a. RuntimeException

b. NumberFormatException

c. Throwable

d. Error

e. Exception

a. RuntimeException

62
New cards

An instance of ___ are unchecked exceptions. Select all that apply.

a. RuntimeException

b. Error

c. NumberFormatException

d. Exception

e. Throwable

a. RuntimeException

b. Error

c. NumberFormatException

63
New cards

What exception type does the following program throw?

public class Test {

public static void main(String[] args) {

System.out.println(1 / 0);

}

}

a. ArrayIndexOutOfBoundsException

b. ClassCastException

c. No exception

d. ArithmeticException

e. StringIndexOutOfBoundsException

d. ArithmeticException

64
New cards

What exception type does the following program throw?

public class Test {

public static void main(String[] args) {

int[] list = new int[5];

System.out.println(list[5]);

}

}

a. ClassCastException

b. ArrayIndexOutOfBoundsException

c. StringIndexOutOfBoundsException

d. No exception

e. ArithmeticException

b. ArrayIndexOutOfBoundsException

65
New cards

What exception type does the following program throw?

public class Test {

public static void main(String[] args) {

String s = "abc";

System.out.println(s.charAt(3));

}

}

a. ClassCastException

b. No exception

c. ArrayIndexOutOfBoundsException

d. ArithmeticException

e. StringIndexOutOfBoundsException

e. StringIndexOutOfBoundsException

66
New cards

What exception type does the following program throw?

public class Test {

public static void main(String[] args) {

Object o = new Object();

String d = (String)o;

}

}

a. ArrayIndexOutOfBoundsException

b. No exception

c. ClassCastException

d. StringIndexOutOfBoundsException

e. ArithmeticException

c. ClassCastException

67
New cards

What exception type does the following program throw?

public class Test {

public static void main(String[] args) {

Object o = null;

System.out.println(o.toString());

}

}

a. ArithmeticException

b. ArrayIndexOutOfBoundsException

c. StringIndexOutOfBoundsException

d. NullPointerException

e. ClassCastException

d. NullPointerException

68
New cards

What exception type does the following program throw?

public class Test {

public static void main(String[] args) {

Object o = null;

System.out.println(o);

}

}

a. ArrayIndexOutOfBoundsException

b. ArithmeticException

c. No exception

d. StringIndexOutOfBoundsException

e. NullPointerException

c. No exception

69
New cards

Which of the following is not an advantage of Java exception handling?

a. Exception handling improves performance.

b. Exception handling simplifies programming because the error-reporting and error-handling code can be placed at the catch block.

c. Java separates exception handling from normal processing tasks.

d. Exception handling makes it possible for the caller's caller to handle the exception.

a. Exception handling improves performance.

70
New cards

a program that automatically traverses the documents on the Web by following the hyperlinks

possible answers:

absolute file name

relative file name

web crawler

directory path

web crawler

71
New cards

the absolute file name without the complete directory path


possible answers:

absolute file name

relative file name

web crawler

directory path

relative file name

72
New cards

the absolute file name minus the relative file name


possible answers:

absolute file name

relative file name

web crawler

directory path

directory path

73
New cards

contains a file name with its complete path and drive letter


possible answers:

absolute file name

relative file name

web crawler

directory path

absolute file name

74
New cards

What are the reasons to create an instance of the File class? Select all that apply.

a. To read/write data from/to a file

b. To obtain the properties of the file such as whether the file can be read, written, or is hidden.

c. To determine whether the file exists.

d. To rename the file.

e. To delete the file.

b. To obtain the properties of the file such as whether the file can be read, written, or is hidden.

c. To determine whether the file exists.

d. To rename the file.

e. To delete the file.

75
New cards

Which of the following statements creates an instance of File on Windows for the file c:\temp.txt?

a. new File("c:/temp.txt")

b. new File("c://temp.txt")

c. new File("c:\\temp.txt")

d. new File("c:\temp.txt")

c. new File("c:\\temp.txt")

76
New cards

Which class contains the method for checking whether a file exists?

a. System

b. File

c. PrintWriter

d. Scanner

b. File

77
New cards

Which class do you use to write data into a text file?

a. PrintWriter

b. File

c. Scanner

d. System

a. PrintWriter

78
New cards

Which class do you use to read data from a text file?

a. Scanner

b. File

c. PrintWriter

d. System

a. Scanner

79
New cards

Which method can be used to write data?

a. rename

b. exist

c. print

d. close

c. print

80
New cards

Which method can be used to read a whole line from the file?

a. nextLine

b. nextInt

c. nextDouble

d. next

a. nextLine

81
New cards

Which method can be used to create an input object for file temp.txt?

a. new Scanner(temp.txt)

b. new Scanner("temp.txt")

c. new Scanner(new File("temp.txt"))

d. new Scanner(File("temp.txt"))

c. new Scanner(new File("temp.txt"))

82
New cards

Which method can be used to create an output object for file temp.txt? Select all that apply.

a. new PrintWriter(new File("temp.txt"))

b. new PrintWriter(temp.txt)

c. new PrintWriter("temp.txt")

d. new PrintWriter(File("temp.txt"))

a. new PrintWriter(new File("temp.txt"))

c. new PrintWriter("temp.txt")

83
New cards

Which of the following statements are correct? Select all that apply.

I:

try (PrintWriter output = new PrintWriter("output.txt")) {

output.println("Welcome to Java");

}

II:

try (PrintWriter output = new PrintWriter("output.txt");) {

output.println("Welcome to Java");

}

III:

PrintWriter output;

try (output = new PrintWriter("output.txt");) {

output.println("Welcome to Java");

}

IV:

try (PrintWriter output = new PrintWriter("output.txt");) {

output.println("Welcome to Java");

}

finally {

output.close();

}

a. I

b. III

c. IV

d. II

a. I

d. II

*Note: Do not select all for this one. You will lose credit, if so.*

Welcome to Java = I & II

84
New cards

Which of the following statements are correct?

I:

File file = new File("input.txt");

try (Scanner input = new Scanner(file)) {

String line = input.nextLine();

}

II:

try (File file = new File("input.txt");

Scanner input = new Scanner(file);) {

String line = input.nextLine();

}

III:

File file;

try (file = new File("input.txt");

Scanner input = new Scanner(file);) {

String line = input.nextLine();

}

IV:

File file;

Scanner input;

try (file = new File("input.txt");

input = new Scanner(file);) {

String line = input.nextLine();

}

a. II

b. IV

c. III

d. I

d. I

Input = I

85
New cards

Suppose you enter 34.3 57.8 789, then press the ENTER key. Analyze the following code.

Scanner input = new Scanner(System.in);

int v1 = input.nextInt();

int v2 = input.nextInt();

String line = input.nextLine();

a. After the last statement is executed, v1 is 34.

b. After the last statement is executed, line contains characters '7', '8', '9'.

c. The program has a runtime error because 34.3 is not an integer.

d. After the last statement is executed, line contains characters '7', '8', '9', '\n'.

c. The program has a runtime error because 34.3 is not an integer.

86
New cards

Suppose you enter 34.3 57.8 789, then press the ENTER key. Analyze the following code.

Scanner input = new Scanner(System.in);

double v1 = input.nextDouble();

double v2 = input.nextDouble();

String line = input.nextLine();

a. After the last statement is executed, line contains characters '7', '8', '9', '\n'.

b. After the last statement is executed, line contains characters ' ', '7', '8', '9', '\n'.

c. After the last statement is executed, line contains characters ' ', '7', '8', '9'.

d. After the last statement is executed, line contains characters '7', '8', '9'.

c. After the last statement is executed, line contains characters ' ', '7', '8', '9'.

87
New cards

Suppose you enter 34.3, the ENTER key, 57.8, the ENTER key. Analyze the following code. Select all that apply.

1 Scanner input = new Scanner(System.in);

2 double v1 = input.nextDouble();

3 double v2 = input.nextDouble();

4 String line = input.nextLine();

a. After line 4 is executed, line contains character "\n".

b. After line 2 is executed, v1 is 34.3.

c. After line 4 is executed, line contains an empty string.

d. After line 4 is executed, line is null.

e. After line 3 is executed, v2 is 57.8.

b. After line 2 is executed, v1 is 34.3.

c. After line 4 is executed, line contains an empty string.

e. After line 3 is executed, v2 is 57.8.

88
New cards

Suppose you enter 34.3, the ENTER key, 57.8, the ENTER key, abc, the Enter key. Analyze the following code. Select all that apply.

1 Scanner input = new Scanner(System.in);

2 double v1 = input.nextDouble();

3 double v2 = input.nextDouble();

4 String line = input.nextLine();

a. After line 2 is executed, v1 is 34.3.

b. After line 4 is executed, line contains character "abc".

c. After line 4 is executed, line is null.

d. After line 4 is executed, line contains an empty string.

e. After line 3 is executed, v2 is 57.8.

a. After line 2 is executed, v1 is 34.3.

d. After line 4 is executed, line contains an empty string.

e. After line 3 is executed, v2 is 57.8.

89
New cards

To create an InputStream to read from a file on a Web server, you use the method ___ in the URL class.

a. openStream();

b. getInputStream();

c. obtainInputStream();

d. connectStream();

a. openStream();

90
New cards

Which of the following class definitions defines a legal abstract class?

a. class A { abstract void unfinished() { } }

b. class A { abstract void unfinished(); }

c. abstract class A { abstract void unfinished(); }

d. public class abstract A { abstract void unfinished(); }

c. abstract class A { abstract void unfinished(); }

91
New cards

Which of the following declares an abstract method in an abstract Java class?

a. public abstract method();

b. public abstract void method();

c. public void abstract method();

d. public void method() {}

e. public abstract void method() {}

b. public abstract void method();

PAVM();

92
New cards

Which of the following statements regarding abstract methods is false?

a. An abstract class can have instances created using the constructor of the abstract class.

b. An abstract class can be extended.

c. A subclass of a non-abstract superclass can be abstract.

d. A subclass can override a concrete method in a superclass to declare it abstract.

e. An abstract class can be used as a data type.

a. An abstract class can have instances created using the constructor of the abstract class.

93
New cards

Which of the following statements regarding abstract methods is false?

a. Abstract classes have constructors.

b. A class that contains abstract methods must be abstract.

c. It is possible to declare an abstract class that contains no abstract methods.

d. An abstract method cannot be contained in a nonabstract class.

e. A data field can be declared abstract.

e. A data field can be declared abstract.

94
New cards

Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a no-arg constructor. Which of the following is correct? Select all that apply.

a. A a = new A();

b. A a = new B();

c. B b = new A();

d. B b = new B();

b. A a = new B();

d. B b = new B();

95
New cards

Assume Calendar calendar = new GregorianCalendar(). ____ returns the month of the year.

a. calendar.get(Calendar.MONTH)

b. calendar.get(Calendar.MONTH_OF_YEAR)

c. calendar.get(Calendar.WEEK_OF_MONTH)

d. calendar.get(Calendar.WEEK_OF_YEAR)

a. calendar.get(Calendar.MONTH)

96
New cards

Assume Calendar calendar = new GregorianCalendar(). ____ returns the week of the year.

a. calendar.get(Calendar.MONTH)

b. calendar.get(Calendar.MONTH_OF_YEAR)

c. calendar.get(Calendar.WEEK_OF_MONTH)

d. calendar.get(Calendar.WEEK_OF_YEAR)

d. calendar.get(Calendar.WEEK_OF_YEAR)

97
New cards

Assume Calendar calendar = new GregorianCalendar(). ____ returns the number of days in a month.

a. calendar.get(Calendar.MONTH)

b. calendar.get(Calendar.MONTH_OF_YEAR)

c. calendar.get(Calendar.WEEK_OF_MONTH)

d. calendar.get(Calendar.WEEK_OF_YEAR)

e. calendar.getActualMaximum(Calendar.DAY_OF_MONTH)

e. calendar.getActualMaximum(Calendar.DAY_OF_MONTH)

98
New cards

Which of the following is a correct interface?

a. interface A { void print() { }; }

b. abstract interface A { print(); }

c. abstract interface A { abstract void print() { };}

d. interface A { void print();}

d. interface A { void print();}

99
New cards

Which of the following are incorrect? Select all that apply.

a. An abstract class contains constructors.

b. The constructors in an abstract class should be protected.

c. The constructors in an abstract class are private.

d. You may declare a final abstract class.

e. An interface may contain constructors.

c. The constructors in an abstract class are private.

d. You may declare a final abstract class.

e. An interface may contain constructors.

100
New cards

____ is not a reference type.

a. A class type

b. An interface type

c. An array type

d. A primitive type

d. A primitive type