Wednesday 28 August 2013

Local Variables...

The variables present in the method known as the Local Variables
they don't have any default value.They must be initialised.
Basic 3 steps for local variable:-

  1. Declaration
  2. Initialisation
  3. Usage

like this

output :- 10


output: 5
                                                                                       5


in the above example , multi declaration of the variable give compile time error you cannot declare variable more than once.


in the above example, you can modify the value of variable ..output:-8
in the above example, you cannot do this compile time error x must be initialised before usage.


wrong order first usage then initialisation gives compile time error....

this is all about local variable.....

6 comments :

  1. Wat will be the output of last program .

    ReplyDelete
    Replies
    1. compile time error because we use x without declaration..........

      Delete
  2. And wat wud be the output .,, if a variable has not been assigned any value ..

    ReplyDelete
    Replies
    1. if a variable is declared inside the main then it will give compile time error and if we declare the variable outside the i.e. globally then it will show the default value.....thanx

      Delete
  3. feel free to ask.........any other doubts just ask and sorry for the late reply........

    ReplyDelete