Final VariablesA final variable is one whose value, once it is set, cannot be changed. Final variables are designated as such by using the final keyword in the variable declaration. Both instance and class variables can be declared final . Final variables are useful for defining constants that have public access but whose values aren't meant to be changed. Example: Using Final VariablesOne problem with the BlackBody class from the "Using Instance and Class Variables" example earlier in this chapter is that since the class variable SIGMA has public access the value of it can be changed. If a user were to change the value of the Stefan-Boltzmann constant, it would have an adverse effect on the accuracy of a radiative heating calculation. To prevent this, the variable SIGMA can be declared to be final . [View full width]
Output ” heating rate is 4.819245000000 |