placeholder image to represent content

Java

Quiz by Swathikaa Rk

Our brand new solo games combine with your quiz, on the same screen

Correct quiz answers unlock more play!

New Quizalize solo game modes
33 questions
Show answers
  • Q1
    Which of the following is NOT a primitive data type in Java?
    double
    int
    boolean
    String
    30s
  • Q2
    What is the output of the following Java code?```int x = 5;int y = 10;int z = x + y;System.out.println(z);```
    10
    20
    15
    5
    30s
  • Q3
    What is the purpose of the `public` access modifier in Java?
    To enable inheritance of a member to subclasses
    To make a member accessible from any other part of the program
    To provide encapsulation of a member
    To restrict access to a member within its own class
    30s
  • Q4
    Which of the following is an example of an object-oriented programming (OOP) principle in Java?
    Loops
    Functions
    Conditionals
    Inheritance
    30s
  • Q5
    What is the purpose of the `break` statement in a Java switch statement?
    To exit the switch block and continue executing the code after the switch
    To skip the current case and move to the next case
    To execute a default case
    To terminate the entire program
    30s
  • Q6
    What is the syntax to declare and initialize an array of integers in Java?
    int[] numbers = [1, 2, 3, 4, 5];
    int[] numbers = {1, 2, 3, 4, 5};
    Array numbers = {1, 2, 3, 4, 5};
    int numbers = {1, 2, 3, 4, 5};
    30s
  • Q7
    Which of the following is NOT a valid identifier name in Java?
    _abc
    my_variable
    $abc
    myVariable
    123abc
    30s
  • Q8
    Which operator is used to compare two values for equality in Java?
    !=
    ==
    =
    ===
    30s
  • Q9
    Which operator is used to perform the modulo operation in Java?
    %
    *
    +
    /
    30s
  • Q10
    Which of the following loops in Java is used when the number of iterations is known?
    do-while loop
    while loop
    enhanced for loop
    for loop
    30s
  • Q11
    What is the purpose of the do-while loop in Java?
    To iterate over elements of an array or collection
    To execute a block of code a specific number of times
    To handle exceptions
    To execute a block of code at least once and then repeat it based on a condition
    30s
  • Q12
    What is the syntax for a basic for loop in Java?
    for (initialization; condition; update) { // code block }
    for (condition; initialization; update) { // code block }
    for (condition; update; initialization) { // code block }
    for (update; initialization; condition) { // code block }
    30s
  • Q13
    What does the continue statement do in a loop?
    Modifies the loop condition
    Terminates the loop prematurely
    Skips the current iteration and moves to the next iteration
    Restarts the loop from the beginning
    30s
  • Q14
    What is the difference between the prefix increment operator (++i) and the postfix increment operator (i++) in a loop?
    The prefix increment operator increments the value of the variable before using it, while the postfix increment operator uses the current value and then increments
    The prefix increment operator only works with integer variables, while the postfix increment operator works with any data type
    The prefix increment operator increments the value of the variable and then assigns it to a new variable, while the postfix increment operator increments the original variable itself
    There is no difference between the prefix and postfix increment operators in a loop
    30s
  • Q15
    What is the default value of the boolean data type in Java?
    false
    null
    true
    0
    false
    30s

Teachers give this quiz to your class