You are on page 1of 14

CSC200 Final Exam

Study online at https://quizlet.com/_3f9nn4

1. A(n) ________ enables a program to read Scanner


data from the user.

2. All import declarations must be placed before the class declaration


________.

3. Each of the following is a relational or equal- =!


ity operator except ________.

4. End-of-line comments that should be ig- 2 forward slashes (//)


nored by the compiler are denoted using
________.

5. Given the Java statement a runtime logic error occurs

number1 = input.nextInt();

in which number1 is an int and input is a


Scanner, which of the following occurs if the
user does not enter a valid int value?

6. Given the Java statement It assigns the value of num-


ber1 to sum.
sum = number1 + number2;

which of the following statements is false?

7. Java's predefined classes are grouped into packages


________.

8. Optional parentheses in expressions are redundant


said to be _________.

9. Portions of statements that contain calcula- expressions


tions are called ________.

10. Programs remember numbers and other variables


data in the computer's memory and access
that data through program elements called
________.
1 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4

11. The body of each class declaration begins {, }


with ________ and ends with ________.

12. The filename for the public class that begins Addition.java
with public class Addition must be ________.

13. The format specifier ________ is a place- %d


holder for an int value.

14. What is the value of result after the following 119


Java statements execute (assume all vari-
ables are of type int)?

a = 4;
b = 12;
c = 37;
d = 51;
result = d % a * c + a % b + a;

15. What will be output after the following Java a<b


statements have been executed (assume all c!=d
variables are of type int)?

a=4;
b=12;
c= 37;
d= 51;
if(a<b)
print
if(a>b)
print
if(d<=c)
print
if (c!=d)
print

16. When method printf requires multiple argu- commas (,)


ments, the arguments are separated with
________.
2 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4

17. Which command compiles the Java source javac Welcome.java


code file Welcome.java?

18. Which command executes the Java class file java Welcome
Welcome.class?

19. Which is the output of the following state- Hello World


ments?
print ("Hello");
println("World");

20. Which of the following escape sequences \r


represents a carriage return?

21. Which of the following is a variable declara- int total;


tion statement?

22. Which of the following is a Scanner method nextInt


for inputting an integer value?

23. Which of the following is the escape charac- \


ter?

24. Which of the following is not a Java primitive real


type?

25. Which of the following is not a compilation Placing a semicolon at the


error? end of the first line of an if
statement.

26. Which of the following is not a valid Java my Value


identifier?

27. Which of the following statements does not int a;


alter the value stored in a memory location?

28. Which of the following statements is false? Variable name identifiers


must begin with a lower-
case letter.

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)

30. Which of the following statements would dis- System.out.println("hellois


play the phrase Java is fun? fun\rJava ");

31. How many times is the body of the loop be- 0


low executed?
int c = 1;
while (c>20)
c--;

32. In an expression containing values of the int, promoted, double


types int and double, the ________ values
are ________ to ________ values for use in
the expression.

33. Local variables must be ________. initialized before their val-


ues are used in an expres-
sion

34. Sentinel-controlled repetition is also known indefinite repetition


as ________.

35. The empty statement is denoted by what parentheses ()


symbol?

36. What does the expression x %= 10 do? Divides x by 10 and stores


the remainder in x.

37. Which of the following is a double-selection if...else


control statement?

38. Which of the following is not a Java key- next


word?

39. Which of the following is not a control struc- declaration structure


ture?

4 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
40. Which of the following is not a primitive String
type?

41. Which of the following operators associates /


from left to right?

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.

43. Which of the following statements is false? Cast operators associate


from right to left and are one
level lower in precedence
than the multiplicative oper-
ators.

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.

46. Counter-controlled repetition requires all of these


________.

47. The control variable of a counter-controlled int


loop should be declared as ________ to pre-
vent errors.

48. To exit out of a loop completely, and resume break statement


the flow of control at the next statement after
the loop, use a ________.

49. Which expression is equivalent to if (!(grade if (grade != sentinelValue)


== sentinelValue))?
5 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4

50. Which formatting flag indicates that the float- comma (,)
ing-point values should be output with a
thousands separator?

51. Which of the following is equivalent to this int total = 0;


code segment? for (int i = 0; i <= 20; total +=
i, i += 2);

52. Which of the following is not a type of repe- loop statement


tition statement in Java?

53. Which of the following statements about a The body of a do...while


do...while repetition statement is true? loop is always executed at
least once.

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.

56. Which statement prints the floating-point System.out.printf("%10.3f",


value 123.456 right justified with a field width 123.456);
of 10?

57. boolean values can be displayed as the %b


words true and false with the ________ for-
mat specifier.

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.

60. Invalid possibilities for array indices include negative integers


________.

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];

66. Types in Java are divided into two cate- reference


gories. The primitive types are boolean, byte,
char, short, int, long, float and double. All
other types are ________ types.

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?

69. An argument type followed by a(n) ________ ellipsis(...)


in a method's parameter list indicates that
the method receives a variable number of
arguments of that particular type.

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.

72. Which of the following sets of statements int[][] items;


creates a multidimensional array with 3 rows, items = new int[?][?];
where the first row contains 1 value, the sec- items[0] = new int[1];
ond row contains 4 items and the final row items[1] = new int[4];
contains 2 items? items[2] = new int[2];

73. Which statement below initializes array int[][] items = {{2, 4}, {6, 8},
items to contain 3 rows and 2 columns? {10, 12}};

74. Arrays are ________. fixed-length entities

75. Which statement correctly passes the array takeArray(items)


items to method takeArray? Array items con-
tains 10 elements.

76. Which method call converts the value in vari- Integer.parseInt(stringVari-


able stringVariable to an integer? able)

77. Which of the following statements about ar- A, B, D


rays are true?
A. An array is a group of variables containing
values that all have the same type.
B. Elements are located by index.
8 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
C. The length of an array c is determined by
the expression c.length();.
D. The zeroth element of array c is specified
by c[0].

78. Consider array items, which contains the val- 0, 2, 4, 6, 12


ues 0, 2, 4, 6 and 8. If method changeAr-
ray is called with the method call changeAr-
ray(items, items[2]), what values are stored
in items after the method has finished exe-
cuting?

79. Which of the following statements is false? Reference-type instance


variables are initialized by
default to the value void.

80. Class Arrays provides method ________ for equals


comparing arrays to determine whether they
have the same contents.

81. In array items, which expression below ac- items[3][4]


cesses the value at row 3 and column 4?

82. Reference-type variables (called references) the location of an object


store ________ in memory.

83. Attempting to access an array element out- ArrayIndexOutOfBoundsEx-


side of the bounds of an array, causes a(n) ception
________.

84. String method __________ connects two concat


String objects and returns a new String ob-
ject

85. Which method call converts the value in vari- Integer.parseInt( stringVari-
able stringVariable to an integer? able ).

86. What is the output? 1

9 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
System.out.println("banana".compare-
To("apple"));

87. The String method substring returns A String

88. To check if a string s contains the prefix true


"Java", you may write:

if (s.charAt(0) == 'J' && s.charAt(1) == 'a' &&


s.charAt(2) == 'v' && s.charAt(3) == 'a') ...

89. Consider the statements below: String r1 = a.concat( b.con-


cat( c ) )
String a = "JAVA: ";

String b = "How to ";

String c = "Program";

Which of the statements below will create the


String r1 = "JAVA: How to Program"?

90. Which of the following is the correct state- "Java".toUpperCase()


ment to return JAVA?

91. s1 and s2 are two Java String objects. Which s1.equals(s2)


one is used to check if s1 and s2 have the
same contents only?

92. For i = "the time for all" and j =


"is the time ".
String c = "Now is the time for all";

The Java statements

String i = c.substring( 7 );

10 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4
String j = c.substring( 4, 15 );

will result in:

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.

94. Consider the following method. "omputer"

public String mystery(String input)

String output = "";

for (int k = 1; k < input.length(); k++)

{ output += input.substring(k, k + 1);

return output;

What is returned as a result of the call mys-


tery ( "computer" ) ?

95. What is the return value of "SELECT".sub- "SELEC"


string(0, 5)?

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?

99. Attempting to access an array element out ArrayIndexOutOfBoundsEx-


of the bounds of an array, a(n) ________ oc- ception
curs.

100. Java requires a ________ call for every ob- constructor


ject that's created.

101. Which of the following statements is false? To call a method of an ob-


ject, follow the object name
with a comma, the method
name and a set of parenthe-
ses containing the method's
arguments.

102. Which of the following statements is false? Instance variables can be


declared anywhere inside a
class.

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.

104. A class instance creation expression con- All of these.


tains:

105. A constructor cannot: Specify return types or re-


turn values.

106. Attributes of a class are also known as: Fields.


12 / 14
CSC200 Final Exam
Study online at https://quizlet.com/_3f9nn4

107. Calling a method of an object requires which the dot separator


item?

108. Every Java application is composed of at public class declaration.


least one:

109. Having a this reference allows: all of these

110. Method headers contain all of the following left brace


except:

111. Set methods are also commonly called mutator, accessor


________ methods and get methods are also
commonly called ________ methods.

112. What is the name of the values the method arguments


call passes to the method for the parame-
ters?

113. What type of methods allow a client of a set methods


class to assign values to a private instance
variable?

114. When implementing a method, use the private


class's set and get methods to access the
class's ________ data.

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 {

....

public Student(String major, int age){

....}

....

119. Which statement is used to create a con- public Circle(int n){...}


structor with one argument for Circle class?

14 / 14

You might also like