C# FAQ: Does CSharp support final classes

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

Does C# support final classes?

In the Java language, a final class is one which can not be extended and cannot be used as a base class. In effect, it is the end of the inheritance hierarchy. Such a class is designated by using the final keyword in the class declaration.

In C#, the sealed keyword has the same effect. The following are examples of classes which are final and cannot be extended:

sealed class Employee             // C# example
{
   int idNumber;
   string lastName;            
   string firstName;               
 
   void calculateOvertime() {}
}
final class Employee               // Java example
{
   int idNumber;
   String lastName;
   String firstName;
 
   void calculateOvertime() {}
}


See also


Personal tools