Syntax of the method
modifier Returns a value type method name (parameter type argument name) { ... Method Body ... return return value;}
Overloading (overload)
/** * Overloaded Overload: * In the same class, multiple methods have the same name, but the parameter types and the number of parameters must be different. * The return value may or may not be the same, but the return value alone cannot be used to determine whether a method exists. */public class Example {public void print () {};//public String print () {}; The parameter type is the same as the previous method, the return value is different and cannot be compiled by public void print (int A) {};p ublic void print (String a) {};}
overriding override
/** * 1. Overriding methods can only exist between parent-child classes, and the parameter list and return type of this method between parent and child classes must be exactly the same * 2. In the overridden method, the permission modifier for the subclass must >= the * 3 of the parent class. When the parent class method is private, the subclass has a method that has the same name that is not part of the method's overwrite, but a method that is redefined inside the subclass * 4. In the overridden method, the subclass throws an exception that requires less than or equal to the exception thrown by the parent class * */class animal{int num;public void Eat () {System.out.println ("fruits");}; private void Run () {System.out.println ("Run");} public void count () throws IOException {}}class lion extends animal{public void eat () {//belongs to overwrite System.out.println ("meat");} public void Run () {//does not belong to the rewrite System.out.println ("Jump");} public void count () throws classnotfoundexception {}; Cannot throw exceptions that are not in the parent class method public void count () throws IOException {}//subclass throws an exception that can be the same as the parent class exception or child exception}
Reference:
Https://www.cnblogs.com/jenkinschan/p/5847470.html
"Java" Overloads (Overload) and overrides (override)