Posts

Showing posts from April, 2012

public abstract sealed class MyFundooClass {}

Ever heard of a class that is abstract as well as sealed? Sounds impossible right? abstract means some functions must be defined in derived class and sealed means class can not be derived. Conflicting statements!!? Well actually the catch is in the meaning of abstract class. Creating abstract class means that instance of a class can not be created. That is why you can have following class in c#: public abstract class MyFundooClass { //abstract class without any abstract members. } So now you are clear that abstract means class can not be instantiated. But what if someone decided to derive your class and create an instance of it? For ex: public class MyFundooClassImpl : MyFundooClass { } .... void SomeFunc() { MyFundooClass obj= new MyFundooClassImpl(); //Ohh some has an instance of MyFundooClass !!?? } Here the sealed keyword comes to rescue. Sealed means class can not be derived. So now you can write your class as public a