Q. What will be the output for the below code?
public interface TestInf{
int i =10;
}

public class Test{
public static void main(String... args){
TestInf.i=12;
System.out.println(TestInf.i);
}
}

  • (A) Compile with error
  • (B) 10
  • (C) 12
  • (D) 12 D. Runtime Exception
πŸ’¬ Discuss
βœ… Correct Answer: (A) Compile with error
Explanation: All the variables declared in interface is implicitly static and final , therefore can't change the value.
Explanation by: Ranjeet
All the variables declared in interface is implicitly static and final , therefore can't change the value.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
170
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Ranjeet
Publisher
πŸ“ˆ
97%
Success Rate