final Keyword — Concept Check
Questions on final Keyword. Apply final to variables (assign-once), methods (no overriding), and classes (no subclassing) to communicate intent and enable JVM optimisations.
Questions in this quiz
7 questions on final Keyword — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In a Java program, you have a final List<String> called 'items'. What operation can you perform on this list without causing a compile error?
- AChange the list to a different type
- BRemove the final keyword from the list declaration
- CReassign the list to a new List object
- DAdd elements to the list
2.A developer declares a final method in a Java class. What is the consequence of this declaration?
- ASubclasses cannot override this method
- BThe method can only be called once
- CThe method becomes immutable
- DThe method cannot be called from outside the class
3.A Java class contains a final static field. Where can this field be initialized?
- AIn any method of the class
- BIn any instance method
- CIn a static initializer block
- DIn the constructor
4.You have a final class in Java. What is a direct implication of this?
- ANo other class can extend this class
- BThe class is automatically immutable
- CThe class cannot be instantiated
- DThe class cannot have any methods
5.In Java 8+, what allows a variable to be used in a lambda expression without being explicitly declared final?
- AThe variable is declared as static
- BThe variable is initialized in a constructor
- CThe variable is part of a final class
- DThe variable is effectively final
6.A Java developer uses a final method in a template method pattern. What is the primary reason for this?
- ATo make the method thread-safe
- BTo ensure the method's behavior remains unchanged
- CTo improve the method's performance
- DTo prevent the method from being called more than once
7.What is a potential JVM optimization benefit of using final methods in Java?
- AFinal methods execute faster than non-final methods
- BFinal methods are automatically parallelized
- CThe JVM can inline calls to final methods
- DFinal methods consume less memory