Skip to content
Related Articles

Related Articles

Improve Article

Java | final keyword | Question 3

  • Last Updated : 28 Jun, 2021




class Main {
 public static void main(String args[]){
    final int i;
    i = 20;
    i = 30;
    System.out.println(i);
 }
}

(A) 30
(B) Compiler Error
(C) Garbage value
(D) 0


Answer: (B)

Explanation: i is assigned a value twice. Final variables can be assigned values only one. Following is the compiler error “Main.java:5: error: variable i might already have been assigned”

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :