6.12 OOP Inheritance-1
Hello, welcome to this new one that will be dedicated to the legacy what is the legacy? Inheritance is ... an object-oriented programming concept that reduces the number of lines of code by reusing ... already existing code. It allows to create a new class, called derived class or daughter class, from an existing ... class called super class or parent class. to do simple inheritance allows A derive class to inherit methods or ... assigns a parent class We will implement the inheritance mechanism in Java through a simple example. But ... first of all it is necessary to understand the difference between them simple inheritance and multiple inheritance certain language of programming oriented ... object allow to make multiple inheritance in other words a derived class can inherit from several classes as I explain ... in the path to the right the derived class which is the mother class there is the girls class which ... will inherit from the mother class and then there is a 3rd class daughters which will inherit from the ... girls class which is in under this is possible for other languages but java does support not ... the multiple inheritance a derived class cannot inherit only from a parent class We want to create two new classes: ... dog and duck these two classes have the same properties and methods as the class to which we put ... other attributes and method We will use the inheritance to not copy the code of the class in the classes ... Animal in the Duck and Dog class . you have to know that duplicating code is never a ... good thing because if a shared functionality evolves, then it will be necessary to modify all classes with the risk ... that one day they will no longer work in a similar way. With the inheritance, we can build the Duck and Dog classes ... as extensions of the Animal class by completing them with the missing elements. to put it simply it is said that ... , the Animal class is the mother class or parent class or even the base class and the ... Duck and Dog class are daughter classes or derived classes Before starting the explanations there is essential point ... namely, an inheritance relationship is represented with an arrow with a closed triangular point. The point of the arrow ... indicates the parent class. As you can see I removed all the methods and attributes that were common to our ... animal class and I kept only those methods and attributes that are not common that is-in dog there are ... color as attributes and age as method and therefore duck there is endurance as attribute By experience, I could ... know that duck dogs must inherit from the animal class, but if you can say "is a ... " or "is a" between two classes then it is very likely that there is an inheritance relationship ... between these two classes. Example: a Duck is an Animal or a Dog is an Animal In the next ... course we will do the practice and through this practice there we will see other notions like the right ... of access the reuse of builders with super it is a key word the reuse of manufacturers with the word-key this where ... lack of constructor without arguments in the parent class we will see these lessons through practice so to ... soon.