Java中方法的重载

来源:互联网 发布:淘宝发票规则 编辑:程序博客网 时间:2024/06/16 08:53
    如果同一个类中包含了两个或两个以上方法名相同、方法参数的个数、顺序或类型不同的方法,则称为方法的重载。public class HelloWorld {    public static void main(String[] args)     {        HelloWorld hello = new HelloWorld();        hello.print();        hello.print("Dragon");        hello.print(2);    }   public void print()   {        System.out.println("无参的print方法");   }   public void print(String name)    {      System.out.println(“带有一个字符串参数,参数值为:" + name);    }    public void print(int age)     {      System.out.println("带有一个整型参数,参数值为:" + age);    }}
原创粉丝点击