Java | final keyword | Question 2
Output of follwoing Java program
class Main { public static void main(String args[]){ final int i; i = 20; System.out.println(i); } } |
chevron_right
filter_none
(A) 20
(B) Compiler Error
(C) 0
(D) Garbage value
Answer: (A)
Explanation: There is no error in the program. final variables can be assigned value only once. In the above program, i is assigned a value as 20, so 20 is printed.
Quiz of this Question
Recommended Posts:
- Java | final keyword | Question 4
- Java | final keyword | Question 3
- Java | final keyword | Question 1
- Unreachable statement using final and non-final variable in Java
- final vs Immutability in Java
- Final local variables in Java
- Instance variable as final in Java
- Final static variable in Java
- Static and non static blank final variables in Java
- Java | Java Packages | Question 3
- Java | Inheritance | Question 2
- Java | Inheritance | Question 3
- Java | Inheritance | Question 4
- Java | Inheritance | Question 5
- Java | Functions | Question 9



