Can we declare private class in namespace
No, Allowing classes to be private to a namespace would achieve no meaningful level of protection. Because private means that the member is only access in the containing class. Since a top-level class has no class containing it; it cannot be private or protected. If you force to create a private class in Namespace, compiler will throw a compile time error "Namespace elements cannot be explicitly declared as private, protected or protected internal" .
There are only two valid declarations for a class at the namespace level, "Internal" and "Public". The only exception to this is nested class, where private visibility means that derived classes will have access to the inner class.
The .Net Framework allows you to define a class within another class. Such class is called a nested class. That means a class can be declared within the scope of another class and it is a member of its enclosing class. More about.... What is nested class ?
Does a derived class inherit the constructors of its base class
Only member variables and member methods can be inherited from one Base Class to Derived Class. Constructors are not inherited because we wouldn't be able to properly analyze how our derived class objects were instantiated. It makes sense if you think of constructors as being a bit like static methods in some respects.
In C#, the 'base' keyword is used to call the base class constructor. Also be aware of the fact that the base class constructor without parameter is automatically run if you don't call any other base class constructor calling arguments explicitly. So calling base() is redundant.
- What is a Class?
- What is an Object?
- Constructors and Destructors
- What Is Inheritance ?
- What are the different types of inheritance ?
- What are Access Modifiers ?
- Why Classes cannot be declared as Protected?
- Difference between Classes and Structures
- Can we use pointers in C# ?
- Why abstract class can't create instance
- Can you prevent your class from being inherited
- Difference between method Overloading and Overriding
- Difference between Early Binding and Late binding
- What is nested class
- What is partial class ?
- What is Virtual Method
- Difference between class and object
- What is Data Encapsulation?
- Object Based Language and OOPs