I have read that derived types are completely different types than their respective parents, however the do inherit all their parents' operations.
In other words, you can pass a derived type A
to a operation that receives as a parameter a type B
which is A
's parent. However, you can't assign a variable of type A
to one of type B
and vice versa.
According to the above, the only difference between derived types and subtypes is the assignment. Is that right?
Derived types only inherit the primitive operations of the type they are derived from.
Technically the type derivation creates a new set of primitive operations, so you can't "pass a derived type A
to a operation that receives as a parameter a type B
which is A
's parent". But the compiler creates operations of the same name and implementation, which work on type A
from the primitive operations of type B
. You can for example remove the inherited operations by explicitly declaring them abstract.