Compile-time constants when using object reference in Java

40 Views Asked by At

I'm learning about compile-time constants and I want to ask you if that instance.maximumLoginAttempts expression is a compile-time constant. I don't think it is because in my opinion instance reference is obtained at runtime, so the compiler doesn't know that the value of instance.maximumLoginAttempts is 5. Is that correct? Thank you!

    public class CompileTimeVariables {
            public final int maximumLoginAttempts = 5;
        
            public static void main(String[] args) {
        
                CompileTimeVariables instance = new CompileTimeVariables();
                System.out.println(instance.maximumLoginAttempts);
            }
   }
0

There are 0 best solutions below