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

  • Home
  • SEARCH
  • 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 6326515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:06:21+00:00 2026-05-24T17:06:21+00:00

I am reading Thinking In Java at the moment and I encountered one small

  • 0

I am reading Thinking In Java at the moment and I encountered one small problem. I am doing exercise 12 from chapter 8.

Create an interface with at least one method, in its own package. Create a class in a >separate package. Add a protected inner class that implements the interface. In a third >package, inherit from your class and, inside a method, return an object of the protected >inner class, upcasting to the interface during the return.

So I created these .java files:

A.java

    package c08;
    public interface A
    {
        void one();
    }

Pr2.java

    package c082;
    import c08.*;
    public class Pr2 
    {
        protected class InPr2 implements A
        {
           public void one() {System.out.println("Pr2.InPr2.one");}
           protected InPr2() {}
        }
    }

Ex.java

    package c083;
    import c082.*;
    import c08.*;
    class Cl extends Pr2
    {
        A foo() 
        {
            InPr2 bar=new InPr2();
            return bar;
        } 
    }

And my NetBeans IDE underlines

    InPr2();

and says that:InPr2() has protected access in C082.Pr2.InPr2 and I am wondering why.
If I didn’t explicitly state that constructor in InPr2 should be protected it would be only accessible in C082 package, but when I am inheriting class Pr2 shoudn’t it be available in class Cl, because InPr2 is protected? Everything is fine when I change constructor to public.

  • 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-24T17:06:21+00:00Added an answer on May 24, 2026 at 5:06 pm

    It should work just fine as you have it, except changing the protected InPr2() {} to public InPr2() { }. In other words “Anyone can instantiate this class IF they can see the class to begin with.”

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

Sidebar

Related Questions

Reading through Thinking in Java i stuck in ex:6 of Inner Classes chapter. Exercise
I've been reading Bruce Eckel's Thinking In Java and in the chapter on generics,
I am reading Thinking in java , Generics. In one example(at paragraph The action
I'm reading Bruce Eckel's Thinking in Java and there's an exercise I'm just not
I've just finished reading the chapter of 'Thinking in Java' concerning type information and
I'm reading Thinking in C++ by Bruce Eckel. In Chapter 15 (Volume 1) under
I'm doing a java application. This are my files so far: Person Interface. has
I've learned programming from Java, then tried to learn one programming language per year,
I am reading Thinking in Java 4th Edition . There described a strange workaround
So I've been thinking (while reading this Java pdf)... I know this may seem

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.