Open In App

Java | final keyword | Question 2

Like Article
Like
Save
Share
Report

Output of following Java program




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


(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


Last Updated : 25 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads