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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:41:48+00:00 2026-05-26T20:41:48+00:00

I am new to Java. I’m a C++ programmer, reading some Java code. I

  • 0

I am new to Java. I’m a C++ programmer, reading some Java code. I have this class definition:

class Container {
    long ID;

    class Contained {
        void foo(){
            long parentID = ID;
        }
    }
}

I see that Contained can access any member of the Container class, simply by name.

I have one question:

What is going on here? In C++ these classes would be unrelated. But in Java, it seems, the contained class object seems to be implicitly tied to the instance of the parent class object.

Thanks
Manish

PS: Sorry, I know I could pick up a book on Java, but I was hoping someone could help me.

  • 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-26T20:41:48+00:00Added an answer on May 26, 2026 at 8:41 pm

    Since the Contained class is not declared as static, it means that it can only exist within an instance of a Container class and hence has access to all of the methods and variables of Container.

    If you had declared Contained as static, it would imitate the C++ usage that you’re more used to — that is, you could have an instance of the nested class without having an instance of Container.

    See Java inner class and static nested class for further details.

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

Sidebar

Related Questions

I am a new Java programmer. The following is my code: public static void
I have this byte code: new java.lang.Object // stack is [newObjectRef] dup // Stack
This code: class RawStringIterator { java.util.Stack<State> stateStack = new java.util.Stack<State>(); RawStringIterator(RawStringIterator i) { stateStack
Consider this code: val foo = if(true) new java.lang.Double(4) else new java.lang.Integer(4) The inferred
I'm a relatively new java programmer and I've been tinkering around with this program
If I make a new Java class as follows: class A { public void
I'm a relatively new Java programmer coming from C++/STL, and am looking for a
I am currently calling the following line of code: java.net.URL connection_url = new java.net.URL(http://<ip
I am a brand new Java developer (I have been working in asp.net) and
HI I am a new java programmer (very new). What I want to do/test

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.