欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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.