Java | final keyword | Question 3

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 Posts:



0 Average Difficulty : 0/5.0
No votes yet.






User Actions