CPS10 Mock Quiz
CPS10 Mock Quiz
a. String
b. ArrayList
c. boolean
d. Scanner
e. System
System.out.print("Code");
System.out.print("Lab");
a. Code Lab
b. Code
Lab
c. CodeLab
d. "CodeLab"
e. LabCode
int n = 3;
n *= 3;
n += 6;
a. 9
b. 12
c. 15
d. 6
e. 18
a. 9.6
b. 9.0
c. 9
d. 6
e. 10
showDate(2024, 6, "May");
Assuming:
a. May 6, 2024
b. 6 May 2024
c. 2024, May 6
d. 6 May, 2024
e. 6, May 2024
10. Given an object book of class Book, how do you get the title?
a. String title = book.getTitle();
b. String title = getTitle(book);
c. String title = book.title();
d. title = book.get();
e. book.getTitle();
a. Alice5
b. Alice23
c. Alice2 + 3
d. Alice 5
e. Alice
a. Liam
b. Olivia
c. Noah
d. Error
e. "name"
a. On
b. Off
c. true
d. null
e. Error
int a = 20;
int b = 15;
if (a > b) {
a = a - b;
}
b = a + b;
a. a = 5, b = 20
b. a = 20, b = 15
c. a = 15, b = 35
d. a = 5, b = 25
e. a = 10, b = 30
16. Which data type should you use to store "true" or "false"?
a. String
b. char
c. boolean
d. int
e. byte
a. 0 1 2
b. 1 2 3
c. 1 2 3 4
d. 2 3 4
e. 0 1 2 3
int x = 10;
if (x != 10) x--;
else x += 2;
a. 8
b. 9
c. 10
d. 12
e. 11
a. 2
b. 1
c. 3
d. 0
e. 8
a. 4
b. 5
c. 6
d. 10
e. 3
27. Which access modifier makes a method only accessible within its own class?
a. public
b. protected
c. private
d. default
e. static
int a = 5;
int b = 10;
System.out.println(a > b || b > a);
a. true
b. false
c. 5
d. 10
e. Error
String s = "Hi";
System.out.println(s.length());
a. 1
b. 2
c. 0
d. 3
e. Error
40. What happens if you try to access an index out of bounds in an array?
a. The value 0 is returned
b. A warning is printed
c. The last element is returned
d. An exception is thrown
e. It wraps to index 0
java
CopyEdit
for (int i = 1; i <= 3; i++) {
System.out.print(i + " ");
}
a. 0 1 2
b. 1 2 3
c. 1 2 3 4
d. 2 3 4
e. 0 1 2 3
50. Which part of a Java program contains the main logic to run?
a. init()
b. run()
c. start()
d. main()
e. launch()