6.17 OOP Methode Overloading and Overrinding
Hello, welcome to this new course we will see the main differences between overloading and override. Method overloading consists of ... providing two or more distinct methods in a class with the same name but different parameters. The ... type of method return can be different or not and this allows us to reuse the same name of ... method Overloading is very convenient, it reduces duplicate code and we don’t need to remember to ... of several method names Overloading has nothing to do with polymorphism but Java developers often make ... reference to overload as polymorphism during compilation. In other words, the compiler decides which method ... will be called based on the name of the method, the type of return and the list of ... arguments. We can use overloading on static and instance methods (we’ll come back to ... the difference between static and instance methods). Usually, Overloading occurs within a single class, but a ... method can also be treated as being overloaded in the subclass of that class. Indeed, a subclass inherits a ... version of the method of the parent class and then the subclassclass may have another overloaded version of the ... method Certain Method Overloading Rule Methods will be considered overloading if they meet the following ... rules they must have the same method name but parameters differ If the methods follow its ... rules, they may or may not have different types of returns or have different access modifiers. Now let’s talk about ... overriding which means overload in French at the end of this explanation I will show you an exmple to ... better understand The overriding method is to define a method in a child class that already exists in the class ... parent with the same signature (same name, same arguments). By extending the parent class, the child class gets all the ... methods defined in the parent class (these methods are also called derived methods). When we override a method, it is ... recommended to put @Override immediately above the method definition. This is an annotation that the compiler reads ... and that will then show us an error if we do not follow the overload rules correctly. We ... cannot override static methods, but only instance methods. There is Some rule for the method ... override A method will be considered overloaded if it follows the following rules It must have the same name and ... the same arguments. It cannot have a lower access modifier.For example, if the parent’s method is protected, ... the use of private in the child is not allowed, but the use of public in the child would be allowed. There are also ... some important points to keep in mind regarding the replacement of methods Only inherited methods can be overloaded, that is to say ... methods can only be overloaded in child classes. Manufacturers and private methods cannot be overloaded ... that is, methods can only be overloaded in the daughter classes. Builders and ... private methods cannot be overloaded. Methods that are final can’t be overloaded either. A subclass ... can use super.suvie of the method() name to call the superclass version of an overloaded method. I hope you ... understood this course so soon.