In oop what is the difference between a subclass and a subtype?
In oop what is the difference between a subclass and a subtype?
I haven't really heard the word subtype used too much but I don't think there is a difference.
Hello,
A subtype is a specialized version of a type. In C++ a derived class is a subtype (subclass) of a base class type. A variable of the derived type could appear anywhere that a variable of the parent type is requested.
Characteristics of a subclass that guarantees it is a subtype:
» Can only add variables and methods or redefine existing methods in a compatible way.
If the subclass hides some of the parent’s variables and functions or modifies them in an incompatible way, then it does not create a subtype.
What is a compatible way?
» By imposing some restrictions on the use of inheritance, the language can ensure substitutability.
If you would like more information, check out the following link: Subtyping vs. Subclassing
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
When you use "subclass" do you mean the MFC and winapi method of subclassing a control? A subtype of another type means you can use the subtype in all situations where the parent type could be used. With C+, you not only have the subtype relation between two class(which should occur with proper inheritance trees), but also have protected and private inheritance.