Friday 15 February 2013

Constant Variables And Read only variables

 Constant Variables
  • Its a variable whose value cannot be modified once after declaration so it is compulsory to initialize the variable at the time of declaration so it is compulsory to initialize the modified once after declaration so it is compulsory to initialize the variable at the time of declaration only and to declare a variable as constant we need to use const
  • The behavior of a constant variable will be similar to the behavior of static variables i.e maintains a single copy by initializing one and only one time immediately once the execution of class starts.
 Read only variables
  • Its a variable whose value cannot be modified once after initialization and should be declared using readonly keyword.
  • As readonly variables cannot be initializing after declaration also i.e it can initialized under a constructor.



No comments:

Post a Comment