重载:
1.方法名称一样
2.参数不一样(个数或类型不同)
方法返回值不作为判断依据,
另外,代码测试是正常,- class TestDemo
- {
- void test( int a,double b,char c)
- {
- System.out.println(a+","+b+","+c);
- }
- int test( int m,char n, double o)
- {
- System.out.println(m+","+n+","+o);
- return 1;
- }
- double test( int x,int y,char z)
- {
- System.out.println(x+","+y+","+z);
- return 1.0;
- }
-
- public static void main (String args[])
- {
- TestDemo td = new TestDemo();
- td.test(1,1.0,'a');
- td.test(1,'a',1.0);
- td.test(1,1,'a');
- }
- }
复制代码 |