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

The Archive Base Latest Questions

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

I know that private inheritance is supported in C++ and only public inheritance is

  • 0

I know that private inheritance is supported in C++ and only public inheritance is supported in C#. I also came across an article which says that private inheritance usually defines a HAS-A relationship and kind of an aggregation relationship between the classes.

EDIT: C++ code for private inheritance:
The “Car has-a Engine” relationship can also be expressed using private inheritance:

class Engine {
 public:
   Engine(int numCylinders);
   void start();                 // Starts this Engine
 };

class Car : private Engine {    // Car has-a Engine
 public:
   Car() : Engine(8) { }         // Initializes this Car with 8 cylinders
   using Engine::start;          // Start this Car by starting its Engine
 };

Now, Is there a way to create a HAS-A relationship between C# classes which is one of the thing that I would like to know – HOW?

Another curious question is why doesn’t C# support the private (and also protected) inheritance ? – Is not supporting multiple implementation inheritance a valid reason or any other?

Is private (and protected) inheritance planned for future versions of C#?

Will supporting the private (and protected) inheritance in C# make it a better and widely used language?

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

    Now, Is there a way to create a HAS-A relationship between C# classes which is one of the thing that I would like to know – HOW?

    Make one class have a field of the other class:

    class Car
    {
        Engine engine;
    }
    

    A car has an engine.

    Another curious question is why doesn’t C# support the private (and also protected) inheritance ?

    You have a box in your basement. You have never once put anything into it. Someone asks you “why is this box empty?” What answer can you possibly give other than that the box is empty because no one ever put anything into it?

    C# doesn’t support private or protected inheritance because no one ever implemented that feature and shipped it to customers. Features are not implemented by default, for free. It’s not like we started C# with private and protected inheritance and then took them out for some good reason. Those features were never there in the first place, and unsurprisingly, they are still not there. Features don’t grow themselves.

    Is not supporting multiple implementation inheritance a valid reason or any other?

    I don’t understand the question.

    Is private (and protected) inheritance planned for future versions of C#?

    No.

    Will supporting the private (and protected) inheritance in C# make it a better language than it is now?

    I don’t think so.

    One of the many problems with inheritance as we typically see it in OOP is that it utterly conflates the “is a kind of” semantic relationship with the “reuses implementation details of” mechanism relationship. Private inheritance partially addresses this problem.

    There are a small number of situations in which I would have really liked to have private inheritance in C#; a recent example was that I had a data structure which was possible to construct generally, but which I did not want to expose to users:

    internal class FancyDataStructure<T> {...}
    

    but only possible to serialize when T was int (for reasons which are not germane to the discussion.) I would have liked to say:

    public class SerializableThingy : private FancyDataStructure<int>
    

    Instead I just made FancyDataStructure<T> a nested type of SerializableThingy and used composition rather than inheritance. There was a small amount of “plumbing” code to write but it worked out just fine.

    I don’t think adding the feature pays for itself; it adds complexity to the language in exchange for a very small benefit of avoiding some trivial plumbing taxes.

    Would supporting the private (and protected) inheritance in C# make it a more widely used language than it is now?

    How could I, or anyone else for that matter, possibly know the answer to that question? StackOverflow is a bad place to ask questions that require a prediction of the future based on a counterfactual. My suggestions:

    • Implement a version of C# with the feature you want. See if it becomes popular. Then you’ll know.
    • Find someone with psychic powers who can predict how the future would be if things were different now. Since predictions based on counterfactuals are automatically true by the rules of deductive logic, the predictions will be accurate.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why would anyone declare a constructor protected? I know that constructors are declared private
I know that there're few differences between struct and class in C++. I also
I came across this issue accidentally when I was going over inheritance and up/down
I want to know which is the default inheritance type in C#. for example,
In OOP why need to put something Private , for example. I know that
I know that I can do something like $int = (int)99; //(int) has a
I know that default cron's behavior is to send normal and error output to
I know that you can insert multiple rows at once, is there a way
I know that |DataDirectory| will resolve to App_Data in an ASP.NET application but is
I know that the MsNLB can be configured to user mulitcast with IGMP. However,

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.