Net-informations.com
SiteMap  | About    

Can we declare private class in namespace

Can we declare private class in namespace in C# VB.Net Asp.net interview questions and answers

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.

public class OuterClass { private class InnerClass { } }

Nested 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

why c# does not inherit the constructor from base class  VB.Net

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.

why c# does not inherit the constructor from base class, Does a derived class inherit the constructors of its base class in C#  VB.Net

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.







net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.