Quiz Completed!
Your Score: 17 / 20
Review Your Answers:
Q1: What is the correct way to declare an integer variable named
'age' in Java?
A. int age; ✓ Correct Answer
B. Age int;
C. variable age int;
D. string age;
Correct Answer: A. int age;
Q2: Which of the following is a valid comment in Java?
A. // This is a comment ✓ Correct Answer
B. * This is a comment *
C. -- This is a comment --
D. \ This is a comment
Correct Answer: A. // This is a comment
Q3: What does '[Link]()' do in Java?
A. Reads input from the user.
B. Prints output to the console. ✓ Correct Answer
C. Declares a new variable.
D. Creates a new class.
Correct Answer: B. Prints output to the console.
Q4: Which of the following is a valid data type in Java?
A. text
B. number
C. boolean ✓ Correct Answer
D. character
Correct Answer: C. boolean
Q5: What is the value of '5 + 3 * 2' in Java?
A. 16
B. 11 ✓ Correct Answer
C. 10
D. 8
Correct Answer: B. 11
Q6: What is a 'class' in Java?
A. A type of variable.
B. A collection of methods. ✗ Your Answer
C. A blueprint for creating objects. ✓ Correct Answer
D. A keyword for looping.
Correct Answer: C. A blueprint for creating objects.
Q7: Which of the following is a valid 'if' statement in Java?
A. if x > 5 then
B. if (x > 5) ✓ Correct Answer
C. if x > 5:
D. if x > 5 {}
Correct Answer: B. if (x > 5)
Q8: What is the purpose of the 'main' method in Java?
A. To declare variables.
B. To define classes.
C. It's the entry point of the program. ✓ Correct Answer
D. To print output.
Correct Answer: C. It's the entry point of the program.
Q9: What does '==' do in Java?
A. Assigns a value.
B. Compares two values for equality. ✓ Correct Answer
C. Creates a new object.
D. Declares a variable.
Correct Answer: B. Compares two values for equality.
Q10: Which of the following is a loop in Java?
A. print
B. if
C. for ✓ Correct Answer
D. class
Correct Answer: C. for
Q11: What does the 'new' keyword do in Java?
A. Creates a new class.
B. Creates a new variable.
C. Creates a new object. ✓ Correct Answer
D. Creates a new method.
Correct Answer: C. Creates a new object.
Q12: What is a 'method' in Java?
A. A type of variable.
B. A block of code that performs a specific task. ✓ Correct Answer
C. A keyword for looping.
D. A way to declare a class.
Correct Answer: B. A block of code that performs a specific task.
Q13: Which of the following is used to store text in Java?
A. int
B. boolean
C. String ✓ Correct Answer
D. double
Correct Answer: C. String
Q14: What will the following code print? `[Link](5 >
3);`
A. 5
B. 3
C. true ✓ Correct Answer
D. false
Correct Answer: C. true
Q15: Which of the following is a relational operator in Java?
A. =
B. +
C. %
D. >= ✓ Correct Answer
Correct Answer: D. >=
Q16: What is the result of `10 % 3` in Java?
A. 3
B. 1 ✓ Correct Answer
C. 0
D. 3.33 ✗ Your Answer
Correct Answer: B. 1
Q17: Which access modifier makes a variable accessible from
anywhere?
A. private
B. protected
C. default
D. public ✓ Correct Answer
Correct Answer: D. public
Q18: What is the purpose of the 'return' keyword?
A. To define a class.
B. To exit a loop. ✗ Your Answer
C. To exit a method and optionally return a value. ✓ Correct Answer
D. To declare a variable.
Correct Answer: C. To exit a method and optionally return a value.
Q19: Which of the following is NOT a primitive data type in Java?
A. int
B. boolean
C. String ✓ Correct Answer
D. double
Correct Answer: C. String
Q20: What does the 'while' loop do?
A. Executes code a fixed number of times.
B. Executes code as long as a condition is true. ✓ Correct Answer
C. Declares a new variable.
D. Defines a class.
Correct Answer: B. Executes code as long as a condition is true.
Go Back to Quiz Selection
DarkCode
Accelerate your coding journey with our comprehensive learning platform and developer resources.
Stay Updated
Your email Join
Learn
Programming Language
Web Development
AI & Data Science
AI & Machine Learning
Practice Quiz
Resources
Tutorials
Cheatsheets
Code Challenges
Developer Tools
Company
About Us
Careers
Contact
Privacy Policy
Terms & Conditions
© 2025 DarkCode. All rights reserved.
DarkCode