物件導向—封裝—重載

來源:互聯網
上載者:User

標籤:

 

 

 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     }

 

 

物件導向—封裝—重載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.