C#.NET inheritance access modes: Does C# support private or protected forms of inheritance (i.e., changing base-member accessibility via an inheritance specifier)? Choose the most accurate statement.

Difficulty: Easy

Correct Answer: Correct — C# has only one inheritance form; you cannot declare private/protected inheritance.

Explanation:


Introduction / Context:
The question contrasts C++ and C#. In C++, you can write class D : private B or class D : protected B to adjust base-member accessibility in the derived type. In C#, inheritance syntax does not support such specifiers for classes, so there is no notion of “private” or “protected” inheritance for classes.


Given Data / Assumptions:

  • We are discussing class inheritance in C#.
  • C# allows a single base class and multiple interfaces.
  • Accessibility of inherited members is governed by their declared access modifiers and by the derived class’s context, not by an inheritance-mode keyword.


Concept / Approach:
The C# class declaration syntax uses a colon followed by the base class name (if any) and implemented interfaces. There is no grammar to place private or protected before the base class name to alter how members are exposed. Public, protected, internal, and private modifiers control member accessibility in the declaring class, and derived classes observe those rules; inheritance itself has no “mode” to tighten them for the derived public surface.


Step-by-Step Solution:

class Derived : Base { } → valid; no inheritance mode keyword. Attempt class Derived : private Base { } → invalid in C#. Member accessibility remains determined by each member’s modifier and assembly boundaries.


Verification / Alternative check:
Compiling a “private inheritance” attempt in C# yields syntax errors. Interfaces can be listed freely, but again, no inheritance-mode keywords exist for classes.


Why Other Options Are Wrong:

  • Claims that C# supports private/protected inheritance: false.
  • “Only for interfaces”: interfaces are implemented, not inherited with access modes.
  • “Protected inheritance is default”: non-existent in the language.
  • Abstract base does not change the rule.


Common Pitfalls:
Projecting C++ features onto C#, or confusing member access modifiers with inheritance-mode specifiers.


Final Answer:
Correct — C# has only one inheritance form; you cannot declare private/protected inheritance.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion