Interactive practice · 10 questions on Java syntax, primitives, collections, exceptions, and OOP — easy to hard, with step-by-step explanations.
Press Check answer on each question to see whether you got it right — every check is timestamped and recorded in your Activity log below.
Each attempt is saved under its own name — load, rename, or delete them below. Difficulty / calculator tags are shared across all attempts. Numeric answers accept equivalent forms (e.g. 4/3 or 1.333).
The timer is stopped. Questions are hidden until you resume.
Easy Which keyword declares a class in Java?
Answer: C — class
class, e.g. public class Dog { }.Easy What is the correct signature of a Java program's entry point?
Answer: C — public static void main(String[] args)
public static void main(String[] args) to start the program.Easy What does this print?
System.out.println(3 + 4 + "5");Answer: D — 75
3 + 4 are both int ⇒ 7.7 + "5" concatenates ⇒ "75".Medium Which of these are Java primitive types? Select all that apply.
Answer: A, B, D
int, boolean, double are primitives.String is a class (reference type), not a primitive.Medium Which collection stores unique elements with no duplicates?
Answer: B — HashSet
Set (e.g. HashSet) rejects duplicate elements; lists allow them.Medium What does 7 / 2 evaluate to in Java?
Answer: D — 3
int, so this is integer division — the fractional part is dropped.7 / 2 = 3. (Use 7.0 / 2 for 3.5.)Medium To compare the contents of two String objects, you should use:
Answer: C — .equals()
== compares object references (identity)..equals() compares the actual character contents — use it for strings.Hard Which of these is a checked exception (must be declared or caught)?
Answer: C — IOException
Exception but not RuntimeException; IOException is one.RuntimeExceptions (unchecked).Hard A subclass instance can be used wherever its superclass type is expected. This is called:
Answer: D — Polymorphism
Hard What does this print?
int[] a = {1, 2, 3};
int s = 0;
for (int x : a) s += x;
System.out.println(s);
prints
Answer: 6
for adds each element: 1 + 2 + 3.6.