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

29th May 2018, 8:01 PM
Anjali Srivastav
Anjali Srivastav - avatar
9 odpowiedzi
+ 2
ok thnkxx
30th May 2018, 9:51 AM
Anjali Srivastav
Anjali Srivastav - avatar
0
Could you please explain your problem more accurate?
29th May 2018, 8:42 PM
Jonas Schröter
Jonas Schröter - avatar
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..
29th May 2018, 8:45 PM
Anjali Srivastav
Anjali Srivastav - avatar
0
Could you please post your code here?
29th May 2018, 8:46 PM
Jonas Schröter
Jonas Schröter - avatar
0
ok wait
29th May 2018, 8:46 PM
Anjali Srivastav
Anjali Srivastav - avatar
0
class MyClass { public static final double PI = 3.14; public static void main(String[ ] args) { System.out.println(PI); } }
29th May 2018, 8:48 PM
Anjali Srivastav
Anjali Srivastav - avatar
0
Well, where do you change the value of PI?
29th May 2018, 8:49 PM
Jonas Schröter
Jonas Schröter - avatar
0
class MyClass { public static final double PI = 2.62; public static void main(String[ ] args) { System.out.println(PI); } }
29th May 2018, 8:51 PM
Anjali Srivastav
Anjali Srivastav - avatar
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.
29th May 2018, 8:52 PM
Jonas Schröter
Jonas Schröter - avatar