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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:53:02+00:00 2026-06-04T00:53:02+00:00

Is it possible to have a nested class that is public but can only

  • 0

Is it possible to have a nested class that is public but can only be instantiated by it’s parent class
e.g.

 public class parent
{
    public class child
    {
        public string someValue;
    }

    public child getChild()
    {
        return new child();
    }
}

in this example the ‘child’ class could be instantiated by code external to ‘parent’ . I want the external code to be able to view the ‘child’ type but not be able to construct it’s own one.

e.g

var someChild = new parent.child();
  • 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-04T00:53:03+00:00Added an answer on June 4, 2026 at 12:53 am
    1. Make a public interface.
    2. Make the child class private.
    3. Make the child implement the interface.
    4. Have the getChild method make a new child and return the interface type.

    As mentioned in the comments and other answers, you can also change the access modifier on the constructor(s) of the inner class to either internal or private while leaving the inner class itself public.

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

Sidebar

Related Questions

Is it possible to have multiple classes that inherit/extends same class in Google AppEngine
I have been writing several class templates that contain nested iterator classes, for which
I have several models that includes nested classes and lists. Many of the class
So my Idea is simple - to have a class that can have its
I am trying to test a property that is nested in a child class.
I have a class, which de-constructs incoming string into a nested array cascade .
I have a parent/child relationship via our users table, with models as such: class
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
Is it possible to tie nested generics/captures together? I often have the problem of
I have a Query class that has a number of properties that are collections

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.