Method overload (Overloading method)
Method Overloading is a means for classes to process different types of data in a unified manner. Java method overloading means that multiple methods can be created in the class. They have the same name, but have different parameters and different name definitions. . When a method is called, different numbers and types of parameters are passed to them to determine which method to use. This is polymorphism. The following is an example of method overloading:
Class methodoverloading {
Viod receive (int I ){
System. Out. println ("received one int data ");
System. Out. println ("I =" + I );
}
Viod receive (float f ){
System. Out. println ("received one float data ");
System. Out. println ("F =" + F );
}
Viod receive (string s ){
System. Out. println ("received a string ");
System. Out. println ("s =" + S );
}
}
Note: Java method overloading requires that methods with the same name have different parameter tables. Only different return types are not enough to distinguish two methods with the same name.
overiding method
in Java, subclasses can inherit the methods in the parent class, you do not need to rewrite the same method. But sometimes the subclass does not want to inherit the parent class from the original method, but wants to make some modifications, which requires method rewriting. method rewriting is also called method overwrite. If the method in the subclass has the same method name and return type and parameter table , the new method overwrites the original method.
if you need the original methods of the parent class, you can use the super keyword, which references the parent class of the current class.