URL: Link (1)
According to this wesbite .. you cannot implement Abstract classes but derive from them. This makes sense and I have read this many times.
Like an interface, you cannot implement an instance of an abstract class, however you can implement methods, fields, and properties in the abstract class that can be used by the child class.
But on MSDN
TextWriter is an abstract class but it has two constructors defined … and according to the MS 70-536 book, the following statement is valid:
TextWriter tw = new File.CreateText("myFile.Txt")
The static file class and it’s CreateText method is fine by me as I have studied it on
MSDN but can somebody explain this little contradiction I have found? Surely I am not the first?
Why is instantaion of base abstract classes possible?
All abstract classes have at least one constructor – either you implement one or the compiler generates a parameterless default constructor. The constructor is executed when a derived class is instantiated – it does not matter that the base class is abstract.
But you cannot instantiate an abstract class –
File.CreateText()is a static method and returns an instance of a class derived fromTextWriterbut not aTextWriterinstance.