Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     

.NET interview questions: - How can we stop the class from further inheriting?

We can stop the class from further inheriting by using the "Sealed" keyword. For instance below is a simple sample code where we have a class called as "Human" which is further inherited to create a "Male" or "Female" class.

Now the below code is great but we do not anyone to further inherit from "Male" or "Female" class. In simple words "Male" and "Female" are the last legs in this inheritance hierarchy. This can be done by using the "Sealed" keyword.

public class Human


public sealed class Male : Human


public sealed  class Female : Human


If anyone tries to inherit the sealed classes he will end with the below error "cannot derive from sealed type".

Above is the .NET interview questions & also see the following video on circular dependency: -

Helpful Website Url
Share this article   |    Print    |    Article read by 3959 times
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles:
Related Interview Questions: No related interview question