ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE
What access modifier and finality does a field declared directly inside a Java interface implicitly have?
- A. private final
- B. public, and mutable by any implementing class
- C. protected static
- D. public static final
Correct answer: D. public static final
Fields in an interface are always implicitly public, static and final, i.e. shared constants, whether or not those keywords are written explicitly.
More OOP with C++ and Java questions
- java Function<Integer,Integer> sq = x -> x x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo =…
- What does the 'Rule of Five' in modern C++ say?
- java Function<Integer,Integer> sq = x -> x x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo =…
- java class Base { int v = 1; } class Derived extends Base { int v = 2; } // main: Base b = new Derived(); System.out.print(b.v); What is…
- In C++, a base class constructor calls a function that is overridden in a derived class. Which version actually runs while the base…
- A PaymentMethod type requires every concrete implementation to provide charge() and refund(), but there is no shared implementation at all…