What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 14168 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > C# Interview Questions > Can you allow a class to be inherited, b ...

Can you allow a class to be inherited, but prevent the method from being over-ridden?

Interview question and answer by: Raja | Posted on: 4/27/2008 | Category: C# Interview questions | Views: 3454 |


Answer:

Yes. Just leave the class public and make the method sealed.

Source: http://blogs.crsw.com/mark/articles/252.aspx | Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


 Responses

Posted by: Gryptonite | Posted on: 04 Feb 2013 05:26:34 PM | Points: 10 | Alert Moderator 

Sealed Example:

class A
{
protected virtual void SomeMethod()
{
}
}

class B: A
{
sealed protected override void SomeMethod()
{
}
}

class C: B
{
protected override void SomeMethod() <-- this will cause a comile error since class B has sealed it from being overridden
{
}
}

>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Raja

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 11:14:12 PM