How to restrict a class not to be inherited.?

 Posted by Abhisekjani on 3/22/2011 | Category: C# Interview questions | Views: 6589 | Points: 40

This can be done by declaring the class as sealed class.

Example :

sealed class Abc
class Xyz : Abc //invalid(we can't inherited a sealed class)

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Smartabhisek on: 3/22/2011 | Points: 10
But we can consume the member by creating the object
Posted by: Kishork80 on: 3/22/2011 | Points: 10
If you make the class constructor Private you can achieve the same.It won't allow an object to be created of Parent class.

class Parent
private Parent()
{ }
class Child:Parent

'ConsoleApplication4.Parent.Parent()' is inaccessible due to its protection level

Login to post response

More Interview Questions by Abhisekjani