Sunday, June 2, 2013

Sealed class Modifier

A sealed class modifiers prevents the class from getting inherited, cases marked with sealed cannot be derived by other classes, trying to do so will result in a complier error.

In the following example we try to define a sealed class and try to inherit the same from a derived class.

Abstract Class Modifier

The Abstract Class modifier is used to define base classes which can be derived by other classes. An Abstract class cannot be instantiated i.e we cannot create objects from an Abstract class, trying to do so will result in a compiler error.

Abstract class generally declare only the signature of the methods, the actual method body is coded in the derived class, however it doesn’t not stop us from adding a method body in the abstract class, we can still go ahead and do some code to the method body in the base abstract class.

The following example creates a simple abstract class, and a derived class which inherits from the Abstract class.

New Class Modifier

The new class modifier is used in derived classes when the derived class declared a member with the same name / signature which already exists in the base class.

When a member is declared in the derived class using the same name / signature of a member which already exists in the base class the following warning is thrown.

What are Class Modifiers

Class Modifiers are keywords which are used to add special meaning / purpose to a class. We have seen about access modifiers in the “Access Modifiers” section, access modifiers are general and can be applied to classes and class members, similarly class modifiers are special keywords which can be added to the class definition to alter the behavior of the class.

The following are the class modifiers available in C# .Net

Saturday, June 1, 2013

Access Levels

Access Levels are defined using access modifiers and combinations of access modifiers, access levels define different levels of accessibility to classes and its members by specifying an individual access modifier or combining access modifiers.

The following are the available Access Levels in C#