Can we declare private class in a Namespace?
Submitted by: AdministratorNo. 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.
Submitted by: Administrator
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.
Submitted by: Administrator
Read Online OOP Job Interview Questions And Answers
Top OOP Questions
☺ | What is pure virtual function in OOP? |
☺ | When to use Interface over abstract class? |
☺ | Whats the Difference between Interface and Abstract Class? |
☺ | Can we call a base class method without creating instance? |
☺ | What is Abstract method? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |