+ 3
Please give me a example about final variable in java
3 Answers
+ 12
//example available âș
https://www.sololearn.com/learn/Java/2160/?ref=app
+ 6
Bro, a final variable is a constant or non-variable variable(it was a bit ironical).
for ex.
final int HOUSE_AREA = 5000;
// Area of a house can't change
int cost_per_sqrft = 3400:
// Cost per sqr ft can change with time.
another example.
final int COLUMNS = 5 ;
// No. of columns in a table is fixed.
int ROWS = 10 ;
// Rows can change
one question that came into my mind when I was learning Java was - why we won't use explicit or raw integers directly.
the answer is we can but it creates a messy code if same constant is used many times
that's why we use Math.PI in place of its real value 3.14756848.............
Code better , be best.
0
@JaatPTM . great answer.