NEWEST ORACLE CERTIFIED JAVA
PROGRAMMER EXAM | Q&A WITH
RATIONALES
1. What is the result of the following program?
1: public class Squares {
2: public static long square(int x) {
3: var y = x * (long) x;
4: x = -1;
5: return y;
6: }
7: public static void main(String[] args) {
8: var value = 9;
9: var result = square(value);
10: System.out.println(value);
11: } }
A. -1
B. 9
C. 81
,D. Compiler error on line 9
E. Compiler error on a different line
Correct answer: B
Rationale: Java is pass-by-value, and the
variable `value` on line 8 is never reassigned, so
it remains 9. The `square` method modifies its
own local copy `x`, not the original variable.
2. Which of the following are legal entry point
methods that can be run from the command
line? (Choose all that apply.)
A. private static void main(String[] args)
B. public static final main(String[] args)
C. public void main(String[] args)
D. public static final void main(String[] args)
E. public static void main(String[] args)
F. public static main(String[] args)
Correct answer: D, E
Rationale: Option E is the canonical main
method signature. Option D is also valid as
`final` is redundant but permitted. The method
,must be `public`, `static`, and have a `void`
return type.
3. Which answer options represent the order in
which the following statements can be
assembled into a program that will compile
successfully? (Choose all that apply.)
X: class Rabbit {}
Y: import java.util.*;
Z: package animals;
A. X, Y, Z
B. Y, Z, X
C. Z, Y, X
D. Y, X
E. Z, X
F. X, Z
G. None of the above
Correct answer: C, D, E
Rationale: The correct order is package
(optional), then import (optional), then class. If
, both package and import are present, they must
appear in that order.
4. Which of the following are true? (Choose all
that apply.)
public class Bunny {
public static void main(String[] x) {
Bunny bun = new Bunny();
}}
A. Bunny is a class.
B. bun is a class.
C. main is a class.
D. Bunny is a reference to an object.
E. bun is a reference to an object.
F. main is a reference to an object.
G. The main method doesn't run because the
parameter name is incorrect.
Correct answer: A, E
Rationale: `Bunny` is a class, and `bun` is a
reference variable to an object. The parameter
PROGRAMMER EXAM | Q&A WITH
RATIONALES
1. What is the result of the following program?
1: public class Squares {
2: public static long square(int x) {
3: var y = x * (long) x;
4: x = -1;
5: return y;
6: }
7: public static void main(String[] args) {
8: var value = 9;
9: var result = square(value);
10: System.out.println(value);
11: } }
A. -1
B. 9
C. 81
,D. Compiler error on line 9
E. Compiler error on a different line
Correct answer: B
Rationale: Java is pass-by-value, and the
variable `value` on line 8 is never reassigned, so
it remains 9. The `square` method modifies its
own local copy `x`, not the original variable.
2. Which of the following are legal entry point
methods that can be run from the command
line? (Choose all that apply.)
A. private static void main(String[] args)
B. public static final main(String[] args)
C. public void main(String[] args)
D. public static final void main(String[] args)
E. public static void main(String[] args)
F. public static main(String[] args)
Correct answer: D, E
Rationale: Option E is the canonical main
method signature. Option D is also valid as
`final` is redundant but permitted. The method
,must be `public`, `static`, and have a `void`
return type.
3. Which answer options represent the order in
which the following statements can be
assembled into a program that will compile
successfully? (Choose all that apply.)
X: class Rabbit {}
Y: import java.util.*;
Z: package animals;
A. X, Y, Z
B. Y, Z, X
C. Z, Y, X
D. Y, X
E. Z, X
F. X, Z
G. None of the above
Correct answer: C, D, E
Rationale: The correct order is package
(optional), then import (optional), then class. If
, both package and import are present, they must
appear in that order.
4. Which of the following are true? (Choose all
that apply.)
public class Bunny {
public static void main(String[] x) {
Bunny bun = new Bunny();
}}
A. Bunny is a class.
B. bun is a class.
C. main is a class.
D. Bunny is a reference to an object.
E. bun is a reference to an object.
F. main is a reference to an object.
G. The main method doesn't run because the
parameter name is incorrect.
Correct answer: A, E
Rationale: `Bunny` is a class, and `bun` is a
reference variable to an object. The parameter