Unit 1
Unit 2
Unit 3
Unit 4
Unit 5
100

Which code block prints the string on a different line?

a. System.out.print(“CSA”);

b. System.out.println(CSA);

c. System.out.print(CSA);

d. System.out.println(“CSA”);

d. System.out.println(“CSA”);

100

Class is a _____ for an object. Object is an _____ of the class.



Blueprint, instance

100

What is the output of the following code?

int x = 7;

if (x > 5) {

    if (x % 2 == 0) {

        System.out.println("Even");

    } else {

        System.out.println("Odd");

    }

} else {

    System.out.println("Small");

}


A. Even
B. Odd
C. Small
D. Compile-time error

B. odd

100

Consider the following code segment:

int sum = 0;  

for (int i = 1; i <= 10; i++) {  

    if (i % 2 == 0) {  

        sum += i;  

    }  

}  

System.out.println(sum);

What is printed when the code above is executed?

A) 30
B) 25
C) 20
D) 15
E) 10

A) 30

100

Objects in Java can interact by _____ another object’s methods and _____ another object’s fields.



     Accessing, calling



200

If a variable X of type double is assigned the value 9E307, which expression could result in an unexpected Infinite value due to overflow?

a. x*10

b. X+10

c. A and B

d. None of the above

a. x*10

200

 Identify the error in this code:


String greeting = "Hello";

System.out.println(greeting.charAt(5));




indexOutOfBounds exception

200

What is the output of the following code?

int x = 8;

if (x > 5 && x < 10) {

    System.out.println("Range A");

} else if (x == 10) {

    System.out.println("Range B");

} else {

    System.out.println("Out of Range");

}


A. Range A
B. Range B
C. Out of Range
D. Compile-time error

A. Range A

200

What will the following code print?

for (int i = 1; i <= 3; i++) {

    for (int j = i; j <= 3; j++) {

        System.out.print(i + j + " ");

    }

}


A. 2 3 4 3 4 5 4 5 6

B. 2 3 4 4 5 6 6

C. 3 4 5 6

D. 2 3 3 4 4

A. 2 3 4 3 4 5 4 5 6

200

Heap memory is used to store _____.

a. Variables, primitives, and references

b. Constructors

c. Objects

d. Garbage collection

c. Objects

300

Which statement correctly declares a variable that can store the amount of flour to put in the cupcakes?

a. String amtFlour;

b. int amtFlour;

c. double amtFlour;

d. Double amtFlour;

c. double amtFlour;

300

int a = 10;

int b = 5;

System.out.println(a / b);

a. 2

b. 2.0

c. 5

d. 5.0

b. 2.0

300

Consider the following code:

boolean x = false;

int y = 5;

if (x && y++ > 5) {

    System.out.println("Condition met");

}

System.out.println("y: " + y);


What is the output?
A. Condition met
B. y: 5
C. y: 6
D. Compile-time error

B. y:5

300

What will the following code print?


for (int i = 0; i < 5; i++) {

    int j = i * 2;

    j++;

    System.out.print(j + " ");

}

System.out.println(j);


A. 1 3 5 7 9 and then a compilation error

B. 1 3 5 7 9 10

C. 1 3 5 7 9 and then nothing

D. Compilation error due to j being out of scope.

D. Compilation error due to j being out of scope.

300

What is not a component of encapsulation?

a. Private fields

b. Public getter/setter methods

c. Formal parameters

d. Access modifiers



c. Formal parameters

M
e
n
u