A la distinction déjà vue entre héritage simple et héritage multiple, on ajoute également celle-ci :
En Java, il existe un héritage simple d'implantation et un héritage multiple d'interface. Ainsi le conflit d'opérations sur un objet n'existe pas.
class SC{} Interface I1{} Interface I2{} Interface I3{} class C extends SC implements I1, I2, I3{}
Attention à l'héritage des constructeurs, notamment avec les constructeurs sans arguments et l'utilisation de super().
En Java, les classes abstraites sont possibles, les classes Object
, Class
et ClassLoader
modifient la hiérarchie des classes. Ce qui suit est extrait de la documentation.
java.lang Class Object java.lang.Object public class Object Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
java.lang Class Class java.lang.Object | +--java.lang.Class public final class Class extends Object implements Serializable Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects. Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.
java.lang Class ClassLoader java.lang.Object | +--java.lang.ClassLoader Direct Known Subclasses: SecureClassLoader public abstract class ClassLoader extends Object The class ClassLoader is an abstract class. A class loader is an object that is responsible for loading classes. Given the name of a class, it should attempt to locate or generate data that constitutes a definition for the class. A typical strategy is to transform the name into a file name and then read a "class file" of that name from a file system. Every Class object contains a reference to the ClassLoader that defined it.