Object-oriented programming (OOPs) Question: Download OOP PDF

Can we declare private class in a Namespace?

Tweet Share WhatsApp

Answer:

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.

Download OOP PDF Read All 37 OOP Questions
Previous QuestionNext Question
What is Polymorphism?What is a private constructor? Where will you use it?