首先,编写一个类ChongZai,该类中有3个重载的方法void print();其次, 再编写一个主类来测试ChongZai类的功能。

package a;

public class Chongzai {
    private int i;
    private int j;
    private int k;
    int m;
    

    public int getI() {
        return i;
    }
    public void setI(int i) {
        this.i = i;
    }
    public int getJ() {
        return j;
    }
    public void setJ(int j) {
        this.j = j;
    }
    public int getK() {
        return k;
    }
    public void setK(int k) {
        this.k = k;
    }
    
    public int getM() {
        return m;
    }
    public void setM(int m) {
        this.m = m;
    }
    public void cheng(int i,int j)
    {
         m=i*j;
    }
    public void cheng(int i,int j,int k)
    {
         m=i*j;
    }
    public int cheng()
    {
      m=i*j;
     return m;
    }
    
}
package C;
import a.Chongzai;
public class A {

    public static void main(String[] args) {
    Chongzai a1=new Chongzai();
    a1.setI(2);
    a1.setJ(3);
    a1.cheng();
    System.out.println("m="+a1.getM());
    a1.cheng(3, 4);    
    System.out.println("m="+a1.getM());
    a1.cheng(5, 6, 7);
    System.out.println("m="+a1.getM());
    
    
}

}

posted @ 2016-05-20 21:04  凌零聆  阅读(665)  评论(0编辑  收藏  举报