user3218475 user3218475 - 1 year ago 81
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 Source

Final keyword when used with a class just makes sure that your class cannot be subclassed in your code..a and b refer to two separate 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download