Primitive Types Practice Questions

AP (Advanced Placement) · AP Computer Science A · 148 free MCQs with instant results and detailed explanations.

148
Total
47
Easy
79
Medium
22
Hard

Start Practicing Primitive Types

Take a timed quiz or customize your practice session

Quick Quiz (10 Qs) → Mock Test (25 Qs) ⚙ Customize

Sample Questions from Primitive Types

Here are 10 sample questions. Start a quiz to get randomized questions with scoring.

Q1
Easy
What is the default value of a boolean variable in Java?
A. true
B. false
C. null
D. 0
Show Answer & Explanation
Correct Answer: B
In Java, the default value of a boolean variable when declared but not initialized is 'false'.
Q2
Easy
Which of the following statements correctly assigns an integer value to a variable?
A. int num = '5';
B. int num = 5.0;
C. int num = 5;
D. int num = 5.5;
Show Answer & Explanation
Correct Answer: C
The statement 'int num = 5;' correctly assigns an integer value to the variable 'num'. Other options are invalid assignments for an integer type.
Q3
Easy
What will be the result of the following expression: 10 / 3 in Java?
A. 3.0
B. 3
C. 3.33
D. 10/3
Show Answer & Explanation
Correct Answer: B
In Java, the expression '10 / 3' uses integer division, which results in 3, discarding any fractional part.
Q4
Medium
What will be the output of the following code snippet? int x = 5; System.out.println(x * 2 + x / 2);
A. 10
B. 12
C. 15
D. 13
Show Answer & Explanation
Correct Answer: B
The expression evaluates as follows: x * 2 is 10, x / 2 is 2 (integer division), so 10 + 2 equals 12.
Q5
Medium
If int a = 10 and int b = 3, what will be the result of a % b?
A. 1
B. 3
C. 0
D. 10
Show Answer & Explanation
Correct Answer: A
The modulus operator (%) returns the remainder of the division. 10 divided by 3 gives a remainder of 1.
Q6
Medium
Which of the following statements about the primitive type 'char' is true?
A. It can store any Unicode character.
B. It can only store lowercase letters.
C. It is 2 bytes in size.
D. It cannot represent numerical values.
Show Answer & Explanation
Correct Answer: C
In Java, the char type is a 16-bit Unicode character, which means it is 2 bytes in size.
Q7
Medium
What will be the value of 'y' after executing the code: int x = 5; double y = 2 * x + 1;
A. 10
B. 11.0
C. 11
D. 12
Show Answer & Explanation
Correct Answer: B
The expression 2 * x evaluates to 10, and adding 1 gives 11. When assigned to a double, it retains its decimal representation.
Q8
Hard
Consider the following Java code: boolean x = true; boolean y = false; boolean z = false; boolean result = x && (y || z); System.out.println(result); What will be the output of this code?
A. true
B. false
C. null
D. Compilation error
Show Answer & Explanation
Correct Answer: B
The expression 'y || z' evaluates to false because both y and z are false. Therefore, 'x && false' evaluates to false, which is the value of result.
Q9
Hard
What will be the result of the following code? ```java boolean a = true; boolean b = false; boolean c = a && b; System.out.println(c); ``` A) true B) false C) null D) Compilation Error
A. true
B. false
C. null
D. Compilation Error
Show Answer & Explanation
Correct Answer: B
The logical AND operator (&&) returns true only if both operands are true. Since 'a' is true and 'b' is false, the result c will be false.
Q10
Hard
Consider the following code snippet: ```java byte x = 10; byte y = 20; int z = x * y; System.out.println(z); ``` What will be the output of this code?
A. 200
B. 30
C. 10
D. Error
Show Answer & Explanation
Correct Answer: A
In Java, when performing arithmetic operations, byte values are promoted to int. Therefore, multiplying x (10) and y (20) results in 200, which is stored in the int variable z. The output will be 200.

Showing 10 of 148 questions. Start a quiz to practice all questions with scoring and timer.

Practice All 148 Questions →

Primitive Types โ€” AP (Advanced Placement) AP Computer Science A Practice Questions Online

This page contains 148 practice MCQs for the chapter Primitive Types in AP (Advanced Placement) AP Computer Science A. The questions are organized by difficulty โ€” 47 easy, 79 medium, 22 hard โ€” so you can choose the right level for your preparation.

Every question includes a detailed explanation to help you understand the concept, not just memorize answers. Take a timed quiz to simulate exam conditions, or practice at your own pace with no time limit.