Java Variables

Last Updated :
Discuss
Comments

Question 1

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


  • Variable names can start with a number

  • Variable names can contain special characters like @ or #

  • Variable names are case-sensitive


  • Variable names can be a Java keyword


Question 2

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


  • final int MAX = 100;

  • const int MAX = 100;

  • int const MAX = 100;


  • 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);  }  } } 


  • 20

  • 10

  • Compilation Error


  • Runtime Error


Question 4

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


  • define

  • let

  • int

  • declare

Question 5

Which of the following is a valid integer literal?


  • 12.5

  • 0x1A

  • "100"

  • true

Question 6

Which of these performs explicit type casting?

  • int z = (int) 5.9;

  • double y = 3;

  • int x = 5.0;

  • float f = 5;


Question 7

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

  • 0

  • null

  • garbage value

  • 1

Question 8

Which type of casting happens automatically in Java?


  • Narrowing

  • Widening

  • Reference

  • Explicit

There are 8 questions to complete.

Take a part in the ongoing discussion