it’s simple, i just want a explanation about this:
internal class B { // Base class
}
internal class D : B { // Derived class
}
in other class I wrote:
B b3 = new Object(); //compilation time error!
why??? We suposse that all classes inherit from “object”
Bis more specialized thanObject, therefore you cannot assign anObjectinstance to aBreference. This is because not everyObjectis actually aB– only the opposite is true.Let’s assume that you have a field
xin the classB. When you instantiate anObject, no memory is reserved for this field, and if you could assign it to a reference of typeB, it would therefore try to read or write to unallocated memory, which is not allowed (or useful).