Can we declare private class in a Namespace?

 Posted by Virendradugar on 9/7/2009 | Category: OOPS Interview questions | Views: 13469

No. If you try to create a private class in a Namespace, Compiler will throw a compile time error “Namespace elements cannot be explicitly declared as private, protected, or protected internal”.

Reason: The message says it all. Classes can only be declared as private, protected or protected internal when declared as nested classes, other than that, it doesn't make sense to declare a class with a visibility that makes it unusable, even in the same module. Top level classes cannot be private, they are "internal" by default, and you can just make them public to make them visible from outside your DLL.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response