Java | Variables

05 min read

Variables:

Java variables are classified into 2 types based on the type of data being stored in it.

  • Reference variables (store reference address)      
  • Primitive data type variables (store data)

Based on their scope, they are classified into 3 types:

  • Instance variables — associated with objects and take different values for each Object.
  • Class variables — global to a class & belong to all objects of the class. Only one memory location is created for each class variable.
  • Local variables — variables declared & used inside methods
  • Dynamic initialization of variables is possible in Java. Eg: double c = (a * a + b * b)— (d * d);
POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error