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 8308133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:42:35+00:00 2026-06-08T18:42:35+00:00

Code I have the following class with a member interface: package com.example.withinterface; public class

  • 0

Code

I have the following class with a member interface:

package com.example.withinterface;

public class SomeClass {

    interface SomeInterface {

        void doSomething();
    }
}

And another class trying to access it:

package com.example.withinterface.main;

import com.example.withinterface.SomeClass;

public class Main {

    public static void main(String[] argss) {
        System.out.println(SomeClass.SomeInterface.class);
    }
}

Error

In Main I get the following error from javac: SomeInterface is not public in SomeClass; cannot be accessed from outside package.

And in Eclipse: SomeInterface is not public in SomeClass; cannot be accessed from outside package.

Both compiling as Java 7. Everything compiles fine if I make SomeInterface public.

But Spec says

The Java Language Specification for Java 7 says this:

A member interface is an interface whose declaration is directly
enclosed in another class or interface declaration.

A member interface in a class declaration is implicitly public (§6.6)
unless an access modifier is specified.

The Java Language Specification for Java 5 doesn’t seem to have the second sentence.

Question

So shouldn’t SomeInterface be considered public and shouldn’t Main compile?

Update

As suggested by Ajay George this was indeed an error in the Java Language Specification 7 (thanks JamesB). In the meantime the spec was corrected and the incorrect sentence removed. Last version in Archive.org with the incorrect sentence.

  • 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-06-08T18:42:37+00:00Added an answer on June 8, 2026 at 6:42 pm

    I guess the spec is wrong .
    Here is the javap output with your code.

    E:\workspace>javap com\example\withinterface\SomeClass
    Warning: Binary file com\example\withinterface\SomeClass contains com.example.wi
    thinterface.SomeClass
    Compiled from "SomeClass.java"
    public class com.example.withinterface.SomeClass {
      public com.example.withinterface.SomeClass();
    }
    
    E:\workspace>javap com\example\withinterface\SomeClass$SomeInterface
    Warning: Binary file com\example\withinterface\SomeClass$SomeInterface contains
    com.example.withinterface.SomeClass$SomeInterface
    Compiled from "SomeClass.java"
    interface com.example.withinterface.SomeClass$SomeInterface {
      public abstract void doSomething();
    }
    

    I changed the interface to public and then recompiled it.

    E:\workspace>javap com\example\withinterface\SomeClass
    Warning: Binary file com\example\withinterface\SomeClass contains com.example.wi
    thinterface.SomeClass
    Compiled from "SomeClass.java"
    public class com.example.withinterface.SomeClass {
      public com.example.withinterface.SomeClass();
    }
    
    E:\workspace>javap com\example\withinterface\SomeClass$SomeInterface
    Warning: Binary file com\example\withinterface\SomeClass$SomeInterface contains
    com.example.withinterface.SomeClass$SomeInterface
    Compiled from "SomeClass.java"
    public interface com.example.withinterface.SomeClass$SomeInterface {
      public abstract void doSomething();
    }
    

    Note the difference in the Inner class.

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

Sidebar

Related Questions

I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: class Test { public static void main(String[] args) {
I have the following code: class SomeClass {}; class SomeOtherClass { SomeClass& someObj; public:
I have the following code :- class A : public B { public: _container
I have the following code, partly in Java, partly in Scala: Java: public interface
I have the following code files: public interface IMod { string Name { get;
Suppose I have the following: class dataClass { public: int someData; float moreData; void
Basically, I have the following code: public class MyDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
I have following code class User attr_accessor :name end u = User.new u.name =

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.