Page 28 - JAVA Programming
P. 28
27
Symbolic Constant
Symbolic Constant refer to the variable name having value which
cannot be modified/change during the entire lifetime of the program.
For Example, pi = 3.14 now the pi can be used instead of 3.14. For the
conversion symbolic names are written in CAPITAL to distinguish
from another variable name.
After declaration of symbolic constants, they should not be resigned
any other value. Symbolic constants cannot be declared inside a
method. They should be used only as class data member in the
beginning of the class
Syntax : final data_type symbolic_name=value;
class Circle
{
final double PI=3.14;
int radius;
void accept(int r)
{
radius=r;
}
void display()
{
double area=PI*radius;
System.out.println("Radius is :"+radius)
System.out.println("Area of Circle is :"+area);
}
public static void main(String args[])
{
Circle c=new Circle();
c.accept(5);
c.display();
}
}