Variable Declaration and Initialisation – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #JAVA#3862    siteicon   siteicon  

Variable Declaration and Initialisation

Variable declaration and initialisation varieties are explained here.

Learning Objectives

  • Understanding variable declaration.
  • Declaration along with initilisation.
  • Separate Assignment after declaration.
  • Assignment with a returned value of method.

Source Code

TC++ #3862

Source Code

Run Output


Code Understanding

int x;
This is plain variable declaration. No value has been assigned

This is assignment statement only which works on pre-declared variables only.

int y=20;
This is declaration combined with assignment which is also called initialisation.

int z=y;
This is declaration and initialisation of a variable with another pre-assigned variable.

double d=Math.pow(2,3);
This is declaration and assignment of a variable with return value of a method. The return value should of given variable data type.


  • A variable can assigned with –
    – A Literal value of given data type.
    – A reference to another variable which should be of given data type or possibly convertible data type
    – A call to a method which returns the value of given data type. Some times this is also called dynamic initialisation.
  • The oracle documentation for variable and other definitions can be seen at.

Suggested Filename(s):


sunmitra| Created: 20-Mar-2018 | Updated: 21-Mar-2018|