Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Why do we use Static Nested interface in Java?

Pragya Keshap answered on February 4, 2023 Popularity 3/10 Helpfulness 1/10

Contents


More Related Answers

  • java make all interfaces implement another
  • use of nested class in java
  • Interface Extends Multiple Interface in Java
  • Java Static Nested Class
  • java nested class
  • implement two interfaces java
  • Java Nested Static Class
  • why we can implement more than one interface in java
  • How will you call a static method of an interface in a class
  • nested class in java 8
  • Which of the below is true about Interfaces? Pick ONE option Interface can contain constructors A class can implement just one interface An interface can declare public and protected method only An interface cannot have instance variables
  • What is a Static Method? Why do we need Static methods in Java 8 Interfaces?
  • How will you call a static method of an interface in a class
  • What is a Nested interface?
  • Do we have to explicitly mark a Nested Interface public static?

  • Why do we use Static Nested interface in Java?

    0

    Only the enclosing class can access a Static Nested interface.

    Consider following code in which interface Xyz is enclosed in

    class Abc.

    public class Abc {

    public interface Xyz {

    void callback();

    }

    public static void registerCallback(Xyz xyz) {...}

    }

    // Client Code

    Abc.registerCallback(new Abc.Xyz() {

    public void callback() {...}

    });

    Any code that cannot access Abc can not access interface Xyz also.

    So the purpose of declaring an Inner interface is to restrict its

    access from outside world

    https://www.javatpoint.com/nested-interface#:~:text=The%20nested%20interfaces%20are%20used,can't%20be%20accessed%20directly.

    Popularity 3/10 Helpfulness 1/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.