Symbolic Constants in Java?

Constants  may  appear  repeatedly in number  of places  in the program. Constant  values are assigned  to some names  at   the  beginning  of the program, then the subsequent   use of  these names   in  the  program has the  effect  of  caving  their defined  values  to be  automatically  substituted  in appropriate  points. The  constant  is declared  as  follows:

Syntax : final type  symbolicname= value;
     Eg     final  float     PI  =3.14159;
               final  int  STRENGTH  =100;

Rules :-

symbolic  names take the  some   form  as variable  names. But  they  one written  in capitals  to distance   from variable  names.  This  is only  convention  not a  rule.

After  declaration  of symbolic  constants  they shouldn’t   be  assigned  any other value  with in the  program by using  an  assignment  statement.

For  eg:-    STRENTH  = 200  is  illegal

Symbolic  constants  one  declared  for  types   there  are  not done  in c & c++  where symbolic constants  one defined  using    the  define  statement.

They  can’t be  declared  inside  a  method . they  should be  used  only as class  data members  in  the beginning   of the class.


Java 1943640926520407714

Post a Comment