package com.hanqi.kejian; public class ChongZai { //重载,首先,编写一个类ChongZai,该类中有3个重载的方法void print();其次,再编写一个主类来测试ChongZai类的功能。 public void print(int a,int b) { int i=a; int j=b; System.out.println(i+j); } public void print(double a,double b) { double k=a; double l=b; System.out.println(k*l); } public void print(String a) { System.out.println(a); } } //主类main方法 package com.hanqi.kejian; public class ChongZaitext0918 { public static void main(String[] args) { // TODO Auto-generated method stub ChongZai A=new ChongZai(); A.print(123, 456); A.print(123.5, 10.5); A.print("你好"); } }
运行结果: