Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 653235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:21:34+00:00 2026-05-13T22:21:34+00:00

Is it possible to create an inner class within an interface? If it is

  • 0

Is it possible to create an inner class within an interface?
If it is possible why would we want to create an inner class like that since
we are not going to create any interface objects?

Do these inner classes help in any development process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:21:34+00:00Added an answer on May 13, 2026 at 10:21 pm

    Yes, you can create both a nested class or an inner class inside a Java interface (note that contrarily to popular belief there’s no such thing as an “static inner class“: this simply makes no sense, there’s nothing “inner” and no “outter” class when a nested class is static, so it cannot be “static inner”).

    Anyway, the following compiles fine:

    public interface A {
        class B {
        }
    }
    

    I’ve seen it used to put some kind of “contract checker” directly in the interface definition (well, in the class nested in the interface, that can have static methods, contrarily to the interface itself, which can’t). Looking like this if I recall correctly.

    public interface A {
        static class B {
            public static boolean verifyState( A a ) {
                return (true if object implementing class A looks to be in a valid state)
            }
        }
    }
    

    Note that I’m not commenting on the usefulness of such a thing, I’m simply answering your question: it can be done and this is one kind of use I’ve seen made of it.

    Now I won’t comment on the usefulness of such a construct and from I’ve seen: I’ve seen it, but it’s not a very common construct.

    200KLOC codebase here where this happens exactly zero time (but then we’ve got a lot of other things that we consider bad practices that happen exactly zero time too that other people would find perfectly normal so…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an anonymous inner class that extends another class. What I
Is it possible to create a class within the same file that contains the
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
I want to create a broadcast receiver as an inner class in my main
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create an alert on any view controller after Facebook request:didFailWithError: I have
Consider this code: class Outer { class Inner } In Java it would be
Possible Duplicate: “Cross-thread operation not valid” exception on inner controls I am a beginner
As far as I know this isn't possible. I would like to draw an
I have a situation where I would like to dynamically create an object through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.