Java Variables

Last Updated :
Discuss
Comments

Question 1

Which of the following is true about variable names in Java?


  • A

    Variable names can start with a number

  • B

    Variable names can contain special characters like @ or #

  • C

    Variable names are case-sensitive


  • D

    Variable names can be a Java keyword


Question 2

What is the correct way to declare a constant variable in Java?


  • A

    final int MAX = 100;

  • B

    const int MAX = 100;

  • C

    int const MAX = 100;


  • D

    MAX = 100;

Question 3

What will be the output of this Java program?

Java
public class Demo {
    public static void main(String[] args) {
        int x = 10;
        {
            int x = 20;
            System.out.println(x);
        }
    }
}


  • A

    20

  • B

    10

  • C

    Compilation Error


  • D

    Runtime Error


Question 4

Which keyword is used to declare an integer variable in Java?


  • A

    define

  • B

    let

  • C

    int

  • D

    declare

Question 5

Which of the following is a valid integer literal?


  • A

    12.5

  • B

    0x1A

  • C

    "100"

  • D

    true

Question 6

Which of these performs explicit type casting?

  • A

    int z = (int) 5.9;

  • B

    double y = 3;

  • C

    int x = 5.0;

  • D

    float f = 5;


Question 7

What is the default value of an uninitialized int variable in a class?

  • A

    0

  • B

    null

  • C

    garbage value

  • D

    1

Question 8

Which type of casting happens automatically in Java?


  • A

    Narrowing

  • B

    Widening

  • C

    Reference

  • D

    Explicit

There are 8 questions to complete.

Take a part in the ongoing discussion