CSC200 Final Exam
CSC200 Final Exam
number1 = input.nextInt();
12. The filename for the public class that begins Addition.java
with public class Addition must be ________.
a = 4;
b = 12;
c = 37;
d = 51;
result = d % a * c + a % b + a;
a=4;
b=12;
c= 37;
d= 51;
if(a<b)
print
if(a>b)
print
if(d<=c)
print
if (c!=d)
print
18. Which command executes the Java class file java Welcome
Welcome.class?
3 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
29. Which of the following statements is true? All of these are true. (pack-
age, class names, enter
your age)
4 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
40. Which of the following is not a primitive String
type?
42. Which of the following statements about the The second operand is the
conditional operator (?:) is false? result value if the condition
evaluates to false.
44. Which of the following statements is true? Syntax errors are caught
by the compiler. Logic er-
rors have effects at execu-
tion time.
45. Consider the following two Java code seg- Both The output from these
ments: segments is not the same
and The scope of the con-
trol variable i is different for
the two segments are true.
50. Which formatting flag indicates that the float- comma (,)
ing-point values should be output with a
thousands separator?
54. Which of the following statements about the The break statement, when
break statement is false? executed in a while, for or
do...while, skips the remain-
ing statements in the loop
body and proceeds with the
next iteration of the loop.
55. Which of the following statements about the A continue statement pro-
continue statement is true? ceeds with the next itera-
tion of the immediately en-
closing while, for, do...while
statement.
58. The preferred way to traverse a two-dimen- two nested for statements
sional array is to use ________.
6 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
59. Which of the following statements is false? Variables of type boolean
are initialized to true.
61. Which of the following initializer lists would int[] n = {1, 2, 3, 4, 5};
correctly set the elements of array n?
62. When you pass an array or an individual ar- a copy of the element's ref-
ray element of a reference type to a method, erence, a copy of the ele-
the called method receives ________. When ment's value
you pass an individual element of a primitive
type, the called method receives ________.
63. Which of the following statements about cre- The elements of an array of
ating arrays and initializing their elements is integers have a value of null
false? before they are initialized.
64. Consider the code segment below. Which of The value of g[3] is -1.
the following statements is false?
int[] g;
g = new int[23];
65. What do the following statements do? Create a double array con-
taining 14 elements.
double[] array;
array = new double[14];
67. Which of the following statements creates a int[][] items = {{1}, {2, 3, 4,
multidimensional array with 3 rows, where 5}, {6, 7}};
the first row contains 1 element, the second
row contains 4 elements and the final row
contains 2 elements?
7 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
68. Which expression adds 1 to the element of ++arrayName[i]
array arrayName at index i?
70. When an argument is passed by reference, the called method can ac-
________. cess the argument's value
in the caller directly and
modify that data
71. Which of the following tasks cannot be per- Incrementing the value
formed using an enhanced for loop? stored in each element of
the array.
73. Which statement below initializes array int[][] items = {{2, 4}, {6, 8},
items to contain 3 rows and 2 columns? {10, 12}};
85. Which method call converts the value in vari- Integer.parseInt( stringVari-
able stringVariable to an integer? able ).
9 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
System.out.println("banana".compare-
To("apple"));
String c = "Program";
String i = c.substring( 7 );
10 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
String j = c.substring( 4, 15 );
93. Suppose s is a string with the value "java". Nothing will be assigned
What will be assigned to x if you execute the to x, because the execu-
following code? tion causes the runtime er-
ror StringIndexOutofBound-
char x = s.charAt(4); sException.
return output;
96. The length of a string can be determined by: The String method length()
97. Which of the following is valid array declara- int[] words = new int[10];
tion?
98. sum = 78
11 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
Consider the following code:
int a = 7;
int b = 8;
System.out.println("Sum = " + a + b);
What is output?
103. Which of the following statements is false? Each class declaration that
begins with the access
modifier private must be
stored in a file that has the
same name as the class
and ends with the .java file-
name extension.
115. Which of the following statements is true? methods and instance vari-
ables can both be either
public or private
116. what's wrong with the following code? Class A does not have
no-arg constructor. So you
cannot use new A().
117. what's wrong with the following code? false. (By default, a boolean
data field has a value false)
118.
13 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
Write a statement to create an object using 1. Account acct = new Ac-
a no-arg constructor for a class named Ac- count();
count 2. Student s1 = new Stu-
Write a statement to create an object using dent("Amy", 22);
the constructor defined below:
class Student {
....
....}
....
14 / 14