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 freeSample questions
Which keyword is used to declare a class in Java?
- function
- class
- object
- 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).
Which operator is used for equality comparison in Java?
- =
- ==
- !=
- >=
Show answer
Answer: B. ==
The double equals sign (`==`) is the equality comparison operator in Java. A single equals sign (`=`) is used for assignment.
Which keyword is used to refer to the current instance of a class within a method?
- super
- this
- self
- 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.
Which operator is used for incrementing a variable by one in Java?
- +
- ++
- --
- +=
Show answer
Answer: B. ++
The `++` operator is the increment operator. It increases the value of a variable by 1. The `--` operator is for decrementing.
Which keyword is used to make a class or member accessible from any other class?
- private
- protected
- default (no keyword)
- 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.