Some objects may have similar but not identical attributes and methods. If there is a large
degree of similarity, it would be useful to be able to share the common properties
(attributes and methods). Inheritance allows one class to be defined as a special case of
a more general class. These special cases are known as subclasses and the more general
cases are known as superclasses. The process of forming a superclass is referred to as
generalization and the process of forming a subclass is specialization. By default, a
subclass inherits all the properties of its superclass(es) and, additionally, defines its own
unique properties. However, as we see shortly, a subclass can also redefine inherited
properties. All instances of the subclass are also instances of the superclass. Further, the
principle of substitutability states that we can use an instance of the subclass whenever a
method or a construct expects an instance of the superclass
Some objects may have similar but not identical attributes and methods. If there is a large
degree of similarity, it would be useful to be able to share the common properties
(attributes and methods). Inheritance allows one class to be defined as a special case of
a more general class. These special cases are known as subclasses and the more general
cases are known as superclasses. The process of forming a superclass is referred to as
generalization and the process of forming a subclass is specialization. By default, a
subclass inherits all the properties of its superclass(es) and, additionally, defines its own
unique properties. However, as we see shortly, a subclass can also redefine inherited
properties. All instances of the subclass are also instances of the superclass. Further, the
principle of substitutability states that we can use an instance of the subclass whenever a
method or a construct expects an instance of the superclass
การแปล กรุณารอสักครู่..