12. Method Overloading
程序员文章站
2022-07-15 13:05:08
...
package lesson93;
public class MethodOverloading {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(Add(1,2));
System.out.println(Add(1.8,2.2));
System.out.println(Add("Hello","Java"));
}
public static int Add(int a, int b) {
return (a+b);
}
public static double Add(double a, double b) {
return (a+b);
}
public static String Add(String a, String b) {
return (a+b);
}
}
public class DataArtist {
...
public void draw(String s) {
...
}
public void draw(int i) {
...
}
public void draw(double f) {
...
}
public void draw(int i, double f) {
...
}
}
This is called overloading method, and Java can distinguish between methods with different method signatures.
推荐阅读
-
解析php函数method_exists()与is_callable()的区别
-
设计模式学习笔记:factory method(工厂方法)
-
Method Swizzling
-
大白话工厂方法模式(Factory Method)
-
C# get class and method summary
-
ASP.NET MVC 5 - 验证编辑方法(Edit method)和编辑视图(Edit view)
-
innodb_flush_method取值方法(实例讲解)
-
Laravel - Method [xxx] does not exist on [xxx]
-
报错android.view.InflateException: Binary XML file line #11: Attempt to invoke virtual method 'boolean怎么解决?
-
工厂方法模式-Factory Method