Please give me a example about final variable in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Please give me a example about final variable in java

25th Feb 2018, 4:33 PM
Madhusudhan
Madhusudhan - avatar
3 Answers
25th Feb 2018, 4:50 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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.
25th Feb 2018, 4:56 PM
JaatPTM("Paritosh Malik");
JaatPTM("Paritosh Malik"); - avatar
0
@JaatPTM . great answer.
25th Feb 2018, 8:06 PM
Farshaad Heydari
Farshaad Heydari - avatar