Xpode.com        Click here to Print this article.

.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: -



http://
http://www.questpond.com/

Contributed by:
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 http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=703

Click here to go on website