Can we declare a class protected

why a class cannot be defined as protected in C#

You cannot declare protected classes at the namespace level because the access modifier for outer level classes defines their visibility in relation to other assemblies. The protected visibility is used to indicate 'visible to derived classes'; this makes sense on things inside a class, but normally has no meaning at the class level.

Why Classes cannot be declared as Protected?

private and protected class - why not in C#

There are only two valid declarations for a class at the namespace level, "Internal" and "Public". The only exception to this is an inner class, where protected visibility means that derived classes will have access to the inner class.

public class OuterClass { protected class NestedClass { } }

Nested Class

The .Net Framework allows you to define a class within another class. Such class is called a nested class. Nested classes have access to the private members of the outer class. It is a way of logically grouping classes that are only used in one place. More about.... What is nested class ?

Are private class variables inherited ?

Can you inherit private members of a class in C#

An inherited class has access to the public, protected, internal, and protected internal members of a parent class. Even though a derived class inherits the private members of a base class, members marked private are not accessible to derived classes for integrity purpose. You can access private variables/methods from a derived class using reflection or mark the members as protected.