In Java, when we implement an interface method, it must be declared as :

2015

In Java, when we implement an interface method, it must be declared as :

  1. A.

    Private

  2. B.

    Protected

  3. C.

    Public

  4. D.

    Friend

Attempted by 345 students.

Show answer & explanation

Correct answer: C

Answer: public — The implementing method must be declared public.

Why:

  • Interface methods are implicitly public (and abstract) unless they are declared as default or static.

  • When a class implements an interface method, it cannot reduce the method's visibility. That means the implementing method must be public; declaring it protected or private will cause a compile-time error.

  • Note: Since Java 8, interfaces can have default and static methods. Default methods have an implementation in the interface; if you override a default method in the implementing class, the overriding method still must be public.

Example:

interface MyInterface { void foo(); }

class MyClass implements MyInterface { public void foo() { /* implementation */ } }

Explore the full course: Mppsc Assistant Professor