ProgrammingModerateInfosys · HCL

In Java, an interface declares int MAX = 10;. What happens if an implementing class executes MAX = 20; ?

  1. A. MAX becomes 20 for that object only
  2. B. MAX becomes 20 for all implementing classes
  3. C. It compiles and throws an exception at run time
  4. D. Compile error, because interface fields are implicitly public static final

Correct answer: D. Compile error, because interface fields are implicitly public static final

Fields in an interface are constants: public, static and final by default, so assignment is rejected at compile time.

More OOP with C++ and Java questions

Exams that ask this topic