Variable and Comment in Java 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


a is the correct option




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.


d is the correct option




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


c is the correct option




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.


a is the correct option




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


a is the correct option




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)


c is the correct option