WGU D286 — Java Fundamentals | Comprehensive
Objective Assessment | Study Guide | Latest Update
2026/2027 | Practice Questions and Answers | Exam
Review
Table of Contents
1. Java Basics, Syntax, and Structure
2. Primitive Data Types and Literals
3. Operators and Expressions
4. Control Flow: if/else, switch, and Loops
5. Arrays: One-Dimensional and Multi-Dimensional
6. Methods, Parameters, and Overloading
7. Encapsulation and Access Modifiers
8. Object-Oriented Programming: Classes and Objects
9. Inheritance and Polymorphism
10. Abstract Classes and Interfaces
11. Exception Handling
12. Working with Strings and StringBuilder
13. Collections: ArrayList and Wrapper Classes
14. Static and Final Keywords
15. Code Reading and Output Prediction
, WGU D286 |2
Question 1: Which of the following is the correct entry point for a Java application?
A. public void main(String[] args)
B. public static void main(String[] args)
C. public static int main(String[] args)
D. public static void main()
Correct Answer: B. public static void main(String[] args)
The main method must be declared as public, static, void, and accept a String array
parameter. This exact signature allows the Java Virtual Machine (JVM) to invoke the method
as the starting point of the application. Any other signature will result in a runtime error
stating that the main method is not found.
Question 2: What is the correct way to declare a variable that stores the number of students in
a class?
A. numStudents = 30;
B. int numStudents = 30;
C. integer numStudents = 30;
D. numStudents int = 30;
Correct Answer: B. int numStudents = 30;
In Java, variables must be declared with a data type before use. The int keyword declares an
integer variable. Java is statically typed, meaning every variable must have a declared type.
The syntax is type variableName = value;.
Question 3: What is the output of System.out.println();?
A. 3.3333333333333335
B. 3.0
C. 3
D. 4
Correct Answer: C. 3
When both operands of the division operator are integers, Java performs integer division,
which truncates the decimal portion. The result is 3, not 3.333. To get a decimal result, at
least one operand must be a floating-point type.
Question 4: Which data type would be most appropriate for storing a monetary value with
decimal precision?
, WGU D286 |3
A. int
B. double
C. boolean
D. char
Correct Answer: B. double
The double type is a floating-point type that can store decimal values, making it suitable for
monetary calculations (though BigDecimal is preferred for exact precision). int stores whole
numbers, boolean stores true/false, and char stores a single character.
Question 5: What is the correct way to declare a constant in Java?
A. const int MAX = 100;
B. final int MAX = 100;
C. static int MAX = 100;
D. immutable int MAX = 100;
Correct Answer: B. final int MAX = 100;
The final keyword makes a variable a constant, meaning its value cannot be changed after
initialization. Java does not have a const keyword. By convention, constants are named in
uppercase with underscores. The static keyword is not required for a constant but is often
used for class-level constants.
Question 6: What is the output of System.out.println(5 + 3 * 2);?
A. 16
B. 11
C. 13
D. 10
Correct Answer: B. 11
Java follows the standard order of operations (PEMDAS). Multiplication is performed before
addition. So 3 * 2 = 6, then 5 + 6 = 11. Using parentheses can override the order, e.g., (5 + 3)
* 2 = 16.
Question 7: Which of the following is NOT a primitive data type in Java?
A. int
B. boolean
, WGU D286 |4
C. String
D. double
Correct Answer: C. String
String is a class in Java, not a primitive type. The eight primitive types
are byte, short, int, long, float, double, char, and boolean. String is a reference type that
represents a sequence of characters.
Question 8: What is the range of values that can be stored in a byte variable?
A. -128 to 127
B. -32768 to 32767
C. 0 to 255
D. -2147483648 to 2147483647
Correct Answer: A. -128 to 127
A byte is an 8-bit signed integer, giving it a range of -128 to 127. The short type is 16-bit (-
32768 to 32767), int is 32-bit, and long is 64-bit. Choosing the correct type depends on the
range of values needed.
Question 9: What is the output of System.out.println("Hello" + 5 + 3);?
A. Hello53
B. Hello8
C. Hello 5 3
D. Error
Correct Answer: A. Hello53
When the + operator is used with a string and a number, Java performs string concatenation.
The expression is evaluated left to right: "Hello" + 5 becomes "Hello5", then "Hello5" +
3 becomes "Hello53". To get Hello8, you would need "Hello" + (5 + 3).
Question 10: What is the output of System.out.println("Hello" + (5 + 3));?
A. Hello53
B. Hello8
C. Hello 5 3
D. Error
Correct Answer: B. Hello8
Parentheses change the order of evaluation. The expression (5 + 3) is evaluated first to 8,