1 /*首先,编写一个类ChongZai,该类中有3个重载的方法void print(); 2 其次,再编写一个主类来测试ChongZai类的功能。*/ 3 private int data; 4 public int getData() { 5 return data; 6 } 7 public void setData(int data) { 8 this.data = data; 9 } 10 11 public ChongZai(int data) { 12 super(); 13 this.data = data; 14 } 15 public int add(int a,int b) 16 { 17 return a*b; 18 } 19 public double add(double a,double b) 20 { 21 return a*b; 22 } 23 public int add(int a,int b,int c) 24 { 25 return(add(add(a,b),c)); 26 } 27 public static void main(String[] args) { 28 // TODO 自动生成的方法存根 29 ChongZai chongzai=new ChongZai(1); 30 System.out.println("2*3="+chongzai.add(2, 3)); 31 System.out.println("4*5*6="+chongzai.add(4, 5, 6)); 32 System.out.println("7.6*3.2="+chongzai.add(7.6, 3.2)); 33 }