Final object can be modified but reference variable cannot be changed

java

Solution

You can't change final value using "=" operator. If you do it, you try to change the reference (or primitive) and `final` states that this cannot be changed.

You can change existing object's fields:

public static final User user = NewUser(145);

    public static void main(String[] args)
    {
        user.setId(155);
    }

Problem

A reference variable marked final cant reassigned to different object.The data with in object can be modified but the reference variable cannot be changed. Based on my Understanding I have a created a code below where I am trying to reassign a new UserId of 155.As the Definition goes I am only trying to change data within the object. But the reference is same. ``` public class FinalClass { public static void main(String[] args) { ChildClass objChildClass = new ChildClass(); objChildClass.UserId = 155; } } class ChildClass { public static final int UserId = 145; } ``` I believe I misunderstood the above concept. Kindly explain the same with example. Thanks for Reply.

Original source