A superclass is a class that may be subdivided into multiple subclasses. The attributes of superclasses are inherited by subclasses. The superclass is often referred to as the parent class or the base class.
A class is a type of object that can be instantiated repeatedly. Each instance of the class represents a single object. Instances of a class can have their own unique properties, but they will also share any properties that are defined at the level of the class itself. Classes are used to create custom objects with specific functions.
Every physical object has a class. For example, a chair is a class of object while a table lamp is an instance of a class. At a high level, classes are used to divide up knowledge about how objects work or look. For example, it might be useful to have a class for chairs, another for tables, and so on. Then, when someone wants to make a new kind of object, like a coffee table, they can do so by writing a class for it.
At a low level, classes are used to group together some or all of the variables that describe some aspect of your program. A class file is just a text file that contains definitions of classes. It is usually accompanied by code that uses the classes defined inside the file.
A subclass is a class that is derived from another class (also called a derived class, extended class, or child class). A "superclass" is the class from which the subclass is derived (also called a base class or a parent class). The superclass cannot be directly instantiated; instead, an object of type SubClass is first created and then used as a prototype to create new objects. This is known as object-oriented programming (OOP).
There are two ways that one class can inherit from another class: explicitly using the "extends" keyword or implicitly using the "prototype" property of objects.
Using the "extends" keyword, a subclass specifies that it is a kind of object by adding this phrase to its declaration: "extends". For example, "TextArea extends Control". Here, TextArea is the name of the subclass and Control is the name of the superclass.
The default behavior for any class is to be a non-inherited class. That is, it does not extend anything. To change this behavior, a class must be declared with the "extends" clause. Even if a class is not inherited from, it can use inheritance with other classes to create a hierarchy of classes.
Except for objects, which have no superclass, each class has a single and unique direct superclass (single inheritance). A subclass inherits all of its superclass's members (fields, methods, and nested classes). Inheritance means that a subclass can be used in place of its superclass when instantiating objects of the class hierarchy.
In object-oriented programming, inheritance is the most important concept in determining how to create new classes. When creating a new class, it is necessary to decide what kind of class it will be: nullary (has no parameters), unary (one parameter), binary (two parameters), etc. The choice of whether to use multiple inheritance or not depends on what kind of class is needed and what kinds of classes already exist on which to rely. For example, if two different classes both inherit from a third class, then those three classes are said to exhibit binary inheritance. If only one class exhibits this behavior while the other does not, then they are said to exhibit non-binary inheritance. Multiple inheritance is possible but results in more code and may not behave as expected; therefore, it is recommended only be used if there are several valid choices for how to implement certain features.
Binary and multi-parameterized inheritance are two types of inheritance that are used frequently in programming. In binary inheritance, exactly two classes inherit from another class.