Q1. What is the result?
A. Valid
B. Not valid
C. Compilation fails
D. An IllegalArgumentException is thrown at run time
Answer: C
Q2. Given:
Javac Jump.java
Java Jump crazy elephant is always
What is the result?
A. Lazy lion is jumping
B. Lion is always jumping
C. Crazy elephant is jumping
D. Elephant is always jumping
E. Compilation fails
Answer: B
Q3. Given:
What three modifications are necessary to ensure that the class is being properly encapsulated?
This class is poorly encapsulated. You need to change the circle class to compute and return the area instead.
A. Change the access modifier of the setradius () method to private
B. Change the getArea () method public double getArea () { return area; }
C. When the radius is set in the Circle constructor and the setRadius () method, recomputed the area and store it into the area field
D. Change the getRadius () method:
public double getRadius () {
area = Math.PI * radius * radius;
return radius;
}
Answer: BCD
Q4. What is the result?
A. They match They really match
B. They really match
C. They match
D. Nothing Prints
E. They really match They really match
Answer: B
Q5. Given:
What is the result?
A. 2 4 6 8
B. 2 4 6 8 9
C. 1 3 5 7
D. 1 3 5 7 9
Answer: D
Q6. Given:
What is the result?
A. 2 1
B. 2 1 0
C. null
D. an infinite loop
E. compilation fails
Answer: E
Q7. public class ForTest {
public static void main(String[] args) {
int[] arrar = {1,2,3};
for ( foo ) {
}
}
}
Which three are valid replacements for foo so that the program will compiled and run?
A. int i: array
B. int i = 0; i < 1; i++
C. ;;
D. ; i < 1; i++
E. ; i < 1;
Answer: ABC
Q8. Given the code fragment:
A. 20
B. 25
C. 29
D. Compilation fails
E. An Array Index Out Of Bounds Exception is thrown at runtime
Answer: B
Q9. Given the code fragment:
What is the result?
A. Found Red
B. Found Red
Found Blue
C. Found Red
Found Blue
Found White
D. Found Red
Found Blue
Found White
Found Default
Answer: B
Q10. Given:
What is the result?
A. 2 4 6 8 10 12
B. 2 4 6 8 10 12 14
C. Compilation fails
D. The program prints multiple of 2 infinite times
E. The program prints nothing
Answer: B