-6

Even though String is a final class we can change the value of it like:

String A = "hello";

And in next step:

A = "World";

Here A will be changed.

Whereas in case of a final variable we can't do it like:

final int a =10;
a = 13; //This Will Give Error

This would be a contradiction.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
  • 13
    final class and final variable are different things. – Eran Jan 09 '20 at 13:28
  • "Please Ans as Soon as possible." [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/q/326569/3788176) – Andy Turner Jan 09 '20 at 13:29

1 Answers1

1

This is because when the class is final it means the methods of the class cannot be changed or overridden. If a field is final, then the value cannot be changed after the initial value has been assigned.

Maxdola
  • 1,562
  • 2
  • 10
  • 29