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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:46:23+00:00 2026-06-08T08:46:23+00:00

I’m hoping someone can help me out. I’ve been researching this problem for hours

  • 0

I’m hoping someone can help me out. I’ve been researching this problem for hours and nobody else seems to have had the same issue (that I’ve come across). I must be making some really bonehead mistake.

I’m new to Java and have designed a very simple Java program.

I have an abstract superclass called Student. This Student superclass has 3 extending classes called Graduate, Undergraduate, and PartTime. The Student class has several abstract methods and several non-abstract methods. I’ve verified that all abstract methods defined in Students have been implemented in all 3 extended classes.

Now I’m trying to do something that should be extremely simple. I’m trying to instantiate one of these extended classes. If I do this:

Student student = new Student();

Netbeans says Student is abstract; can't be instantiated. Ok, fine, I understand why abstract classes cannot be instantiated. Then I try this:

Student.Graduate student = new Graduate();

And Netbeans says an enclosing instance that contains studentmanager.Student.Graduate is required (studentmanager is my package name). I can’t figure out what that means. However, I did figure out that I can instantiate Student like this without errors:

Student[] student = new Student[1];

However, if I then try to do the next logical thing:

student[0] = new Graduate();

I get the same an enclosing instance... error.

Bottom line is I’d like to know how I can instantiate Graduate. Can anyone help me out? Any insight would be greatly appreciated!

Thanks.

  • 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-08T08:46:25+00:00Added an answer on June 8, 2026 at 8:46 am

    Did you define Graduate, Undergraduate, and PartTime as inner classes of Student? That is, like this:

    public class Student {
        /* ... */
        public class Graduate extends Student { /* ... */ }
        public class Undergraduate extends Student { /* ... */ }
        public class PartTime extends Student { /* ... */ }
    }
    

    Instances of inner classes have an implicit reference to an instance of the enclosing class, so that it can do things like access the enclosing instance’s private fields and methods. When you try to instantiate an instance of one of the subclasses, the compiler says “Hey, hold up, I don’t know what to set the implicit reference to!” and produces an error.

    There are three possible solutions:

    • You could move the three subclasses out of the Student class into their own top-level classes defined in their own files.
    • You could add the keyword static in front of the declarations of the subclasses. This tells the compiler that you do not want an implicit reference from the inner class to the enclosing class. This will prevent you from doing things like accessing Student‘s private fields and methods from a subclass, but if you don’t need to do that anyway, this is moot.
    • If you do need the subclasses to access private members of Student, you can create an instance of Student and then use this special syntax to create an instance of the inner class.

      Student s = new Student();
      Graduate g = s.new Graduate();

    The s.new in this example tells the compiler that the new instance of Graduate should have an implicit reference to s.

    Note that in this example this is very unlikely to be what you want. It is often useful to have instances of inner classes that can directly modify their enclosing instance’s fields for doing things like updating the state of the enclosing class in response to a callback, but I suspect that is not your intention here.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.