user3218475 user3218475 - 23 days ago 6
Java Question

Final Java Class - New Object reference

Is a & b will result in 2 objects or 1 object reference.

public final class A {
String var1;
String var2;
enum var3;
}
A a = new A("var1","var2",enumVal);//same inputs
A b = new A("var1","var2",enumVal);//same inputs


[PS: equals() & hashcode() methods are overriden so that it will be same for both a & b]

Answer

Final keyword when used with a class just makes sure that your class cannot be subclassed further...so in your code..a and b refer to two separate objects...final keyword has no relation to singular reference

Here is a link explaining the implication of the final keyword in terms of a class, a method and a variable.