Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between superclass and supertype and the difference between subclass and subtype

Are they interchangeable terms? Would you be able to give formal definitions and also examples?

like image 562
John Avatar asked Sep 10 '25 15:09

John


1 Answers

Both terms (superclass and supertype) are related, but they are not exactly interchangeable.

Only classes have superclasses, while other classifiers have supertypes. Since Class is also a Classifier, a superclass is always a supertype (because superclass redefines the general association between classifiers), but the opposite is not true.

For instance, the primitive type long in Java is defined as a supertype of int. Since primitive types are not classes, long is not a superclass of int.

Another example: in UML, components and interfaces are different from classes (all of them are classifiers), then it is not correct to say "the superclass of a component" but "the supertype of a component".

like image 51
Javier Avatar answered Sep 13 '25 07:09

Javier