Variable in Java MCQs Exercise I

Ques 1 Variable


Which keyword in Java 10 allows you to declare variables without specifying their types explicitly?

A var
B let
C dynamic
D auto

Ques 2 Variable


In Java, variables are case-sensitive. What does this mean?

A Variable names cannot contain uppercase letters.
B Variable names cannot contain lowercase letters.
C Variable names must be in camel case.
D Variable names are distinguished by the use of uppercase and lowercase letters.

Ques 3 Variable


What will be the result of the following code snippet?

int x = 5;
int y = x++;
System.out.println(y);

A 3
B 5
C 7
D Compilation error

Ques 4 Variable


Which of the following statements is true about comments in Java?

A Comments are ignored by the compiler and do not affect the execution of the program.
B Comments are executed as part of the program.
C Comments can only be used to explain the purpose of the program to other programmers.
D Comments are mandatory in every Java program.

Ques 5 Variable


What is the purpose of single-line comments in Java?

A To temporarily disable a piece of code
B To provide documentation for a method or class
C To define a block of code that should be executed
D To improve the performance of the program

Ques 6 Variable


Which of the following is not a valid way to comment out a block of code in Java?

A // code here
// code here
B /* code here /
C /* code here code here */
D