Any2Quiz
Computer Science / Languages / Java

Syntax Quiz - Languages Java

Free practice quiz: Syntax (Languages Java). 51 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

Play all 51 questions free

Sample questions

  1. Which keyword is used to declare a class in Java?

    1. function
    2. class
    3. object
    4. prototype
    Show answer

    Answer: B. class

    In Java, the `class` keyword is used to define a blueprint for creating objects, encapsulating data (fields) and methods (behavior).

  2. Which operator is used for equality comparison in Java?

    1. =
    2. ==
    3. !=
    4. >=
    Show answer

    Answer: B. ==

    The double equals sign (`==`) is the equality comparison operator in Java. A single equals sign (`=`) is used for assignment.

  3. Which keyword is used to refer to the current instance of a class within a method?

    1. super
    2. this
    3. self
    4. current
    Show answer

    Answer: B. this

    The `this` keyword refers to the current object or instance of the class. It's often used to disambiguate between instance variables and local variables or parameters with the same name.

  4. Which operator is used for incrementing a variable by one in Java?

    1. +
    2. ++
    3. --
    4. +=
    Show answer

    Answer: B. ++

    The `++` operator is the increment operator. It increases the value of a variable by 1. The `--` operator is for decrementing.

  5. Which keyword is used to make a class or member accessible from any other class?

    1. private
    2. protected
    3. default (no keyword)
    4. public
    Show answer

    Answer: D. public

    The `public` access modifier makes a class, method, or variable accessible from any other class, regardless of its package.

Take the full quiz

More quizzes

Browse all Java quizzes