Sealed Class in C#
Sealed Class
It is a type of class that cannot be inherited.
The following ar some key points:
public sealed class CustoMerDetails
{
public string AccountIno()
{
return "Vithal Wadje";
}
}
In the preceding example, the class is declared using the sealed keyword so that this class and the class member cannot be inherited
Private Vs sealed class
It is a type of class that cannot be inherited.
The following ar some key points:
- A Sealed class is created by using the sealed keyword
- The Access modifiers are not applied upon the sealed class
- To access the members of the sealed we need to create the object of that class
- To restrict the class from being inherited, the sealed keyword is used
public sealed class CustoMerDetails
{
public string AccountIno()
{
return "Vithal Wadje";
}
}
In the preceding example, the class is declared using the sealed keyword so that this class and the class member cannot be inherited
Private Vs sealed class
Private | Sealed |
Private classes cannot be declared directly inside the namespace. | Sealed classes can be declared directly inside the namespace. |
We cannot create an instance of a private class. | We can create the instance of sealed class. |
Private Class members are only accessible within a declared class. | Sealed class members are accessible outside the class through object. |
Subscribe to:
Posts (Atom)