How to prevent inheritance for some methods?!

Posted by Dr TJ on Stack Overflow See other posts from Stack Overflow or by Dr TJ
Published on 2010-09-22T18:09:34Z Indexed on 2011/02/17 23:25 UTC
Read the original article Hit count: 237

Filed under:
|
|
|

Hi
How can I prevent inheritance of some methods or properties in derived classes?!


public class BaseClass : Collection   
{  
    //Some operations...  
    //Should not let derived classes inherit 'Add' method.  
}

public class DerivedClass : BaseClass      
{        
    public void DoSomething(int Item)      
    {      
        this.Add(Item); // Error: No such method should exist...      
    }      
}  

© Stack Overflow or respective owner

Related posts about c#

Related posts about oop