0
herefinal is written for const Value then if i changes the value of PI then it should be error then how its givingtheuser value
9 Réponses
+ 2
ok thnkxx
0
Could you please explain your problem more accurate?
0
i want to know that declaration of final means the value will be constant but here in the program if i change the value of PI it should give output erroneous but here the output gives the value which i had given..
0
Could you please post your code here?
0
ok wait
0
class MyClass {
public static final double PI = 3.14;
public static void main(String[ ] args) {
System.out.println(PI);
}
}
0
Well, where do you change the value of PI?
0
class MyClass {
public static final double PI = 2.62;
public static void main(String[ ] args) {
System.out.println(PI);
}
}
0
In line 2, you assign the value 3.14 to PI. In line 4 you do not change it, you get and print it. When a final variable is created, you have to assign a value to it.