Java Quiz for Beginners

Questions: 16 · 10 minutes
1. Which method serves as the usual entry point when a Java application is launched by the JVM?
public void start(String[] args)
public static void main(String[] args)
static int main(String args)
public static void run()
2. In the condition `value != 0 && 10 / value > 2`, why does setting `value` to zero not cause division by zero?
Java automatically changes zero to one during division
Integer division by zero returns zero inside a condition
The `&&` operator evaluates the division before checking `value`
The second expression is skipped when the first expression is false
3. What value is printed after this loop finishes? int total = 0; for (int i = 1; i <= 3; i++) { total += i; } System.out.println(total);
6
4
7
3
4. Given this method, what value does the expression `twice(4) + 1` produce? static int twice(int n) { return n * 2; }
8
9
A compile-time error because methods cannot return calculations
10
5. An array is declared as `int[] scores = {10, 20, 30};`. Which value is retrieved by `scores[1]`?
10
20
30
An array index exception is thrown
6. Which keyword declares that one Java class inherits from another class?
instanceof
implements
inherits
extends
7. Which access modifier restricts a field or method to the class in which it is declared?
public
protected
private
static
8. A `switch` starts at `case 2` in the code below. What characters are printed? int code = 2; switch (code) { case 1: System.out.print(""A""); case 2: System.out.print(""B""); case 3: System.out.print(""C""); break; default: System.out.print(""D""); }
B
BC
ABC
BD
9. What is the main purpose of a `catch` block in Java?
To prevent every exception from occurring
To repeat the associated `try` block until it succeeds
To handle a matching exception thrown while the associated `try` block runs
To declare that a method returns an exception
10. You have declared `ArrayList<String> names = new ArrayList<>();`. Which statement adds `""Maya""` to the list?
names.append(""Maya"");
names.insert(""Maya"");
names.add(""Maya"");
names.push(""Maya"");
11. Which statement correctly describes a Java constructor?
It can run only after an object has already been fully created
It must be named `constructor` and return the new object
It has the same name as its class and does not declare a return type
It must be declared `static` so the class can call it
12. A program evaluates `int result = 7 / 2;` and then prints `result`. Which value appears?
3.5
The code does not compile because division requires double values
4
3
13. Two `String` variables may refer to different objects, but you need to compare the text they contain. Which expression should you use?
Assign one variable to the other with `first = second`
Compare the references with `first == second`
Call a nonexistent `first.compare(second)` method
Compare the contents with `first.equals(second)`
14. After the enhanced `for` loop below processes every array element, what value is stored in `sum`? int sum = 0; int[] values = {2, 4, 6}; for (int value : values) { sum += value; }
12
10
24
6
15. A local variable is declared and read inside a method as shown below. What happens? int count; System.out.println(count);
The code fails to compile because the local variable may not have been initialized
The code prints `null` because `count` has not been assigned
The code prints an unpredictable integer left in memory
The code prints `0` because every numeric variable receives a default value
16. Which Java type is designed to store only `true` or `false`?
boolean
bit
int
String
Popular tests
Narcissistic Personality Inventory (NPI)
This self-report measure is used to assess narcissism as a personality trai…
Start Test
Yale-Brown Obsessive Compulsive Scale (Y-BOCS)
This measure is used to rapidly quantify the current severity of obsessive…
Start Test
CRAFFT Screening Test (CRAFFT 2.1)
This brief screening measure is designed to identify potential alcohol and…
Start Test
Patient Health Questionnaire-9 (PHQ-9)
This measure is commonly used to quickly screen for the presence and severi…
Start Test
Maslach Burnout Inventory (MBI)
This self-report measure is used to assess occupational burnout symptoms in…
Start Test
Adolescent Anxiety Questionnaire
This measure is designed to support a brief appraisal of anxiety symptoms a…
Start Test
Emotional Creativity Inventory (ECI)
This self-report measure assesses individual differences in the originality…
Start Test
Horne–Ostberg Morningness–Eveningness Questionnaire (MEQ)
Circadian preferences influence typical patterns of alertness and sleep tim…
Start Test
Ambivalent Sexism Inventory (ASI)
This measure is designed to assess attitudes toward women, including both o…
Start Test
Internalized Misogyny Scale (IMS)
This measure is designed to assess internalized negative beliefs and stereo…
Start Test
Perceived Stress Scale (PSS-10)
This self-report measure assesses the degree to which individuals appraise…
Start Test
Impulsive Behavior Scale (SUPPS-P)
Impulsivity is a multidimensional construct that is often assessed with bri…
Start Test
Clinical Institute Withdrawal Assessment for Alcohol, Revised (CIWA-Ar)
This rating scale is used to rapidly assess the severity of alcohol withdra…
Start Test
Positive and Negative Affect Schedule (PANAS)
This measure provides a brief self-report assessment of current or typical…
Start Test
Light Triad Scale (LTS)
This self-report measure assesses prosocial personality tendencies and orie…
Start Test
Suicidal Ideation Scale
In clinical settings, the Suicidal Ideation Scale is used to structure an i…
Start Test
Body Dysmorphic Disorder Scale (BDD-D)
This brief self-report measure is designed to screen for and quantify distr…
Start Test
Beck Anxiety Inventory (BAI)
This measure is a brief self-report inventory used to screen for anxiety sy…
Start Test
Differential Test of Perfectionism
This instrument is used to screen for perfectionism-related attitudes and t…
Start Test
Locus of Control Scale
This measure assesses generalized expectancies regarding the degree to whic…
Start Test
New Apathy Scale
This brief self-report measure is used to screen for apathy-related symptom…
Start Test
Perth Alexithymia Questionnaire (PAQ)
This measure assesses individual differences in alexithymia, including diff…
Start Test
Social Intelligence Scale
This brief self-report measure is designed to support rapid screening of in…
Start Test
Fear Test
This measure is designed to evaluate individual differences in fear-related…
Start Test
Neuroticism Level Scale
The measure is intended for brief screening of an individual’s propensity t…
Start Test
Aggressiveness Indicators Screening Questionnaire
This screening tool is designed to quickly identify behavioral indicators a…
Start Test