一、Java學習中的總結---方法的使用

來源:互聯網
上載者:User

標籤:color   int   void   java   ges   stat   總結   策略   應用   

 2018-08-1017:16:36

方法的優點:方法的使用可以使代碼易懂、易閱讀、易調試最關鍵的是可以大大的減少代碼的重複性,使代碼具有可重用性 :

public class name(){    public static void main(String[] arges){            int n=max(x,y);                  }    public static int max(int n, int m){               return n+m;   }    }                         

 其中的public static 作為標識符;int屬於傳回值類型;max則屬於方法的名,而max中的(int n,int m)則屬於形式參數,而在main方法中的max()則是實際參數,其中main方法的傳回值類型是void。

 

重載方法:重載方法使得可以在同樣的名字來定義不同傳回值類型的方法,其中的形式參數則可以是不同的數實值型別。

 

public static int max(double n,double m)public static double max(double n,double m)public static double max(int x,double y, String z)

 

方法抽象:方法抽象是通過方法的使用和實現分離來實現的,方法抽象的概念可以應用與程式的開發過程中。可以使用‘分治’策略,也稱之為逐步求精,將大問題分解成子問題,子問題又可以分解成更小、更容易處理的問題。

 

一、Java學習中的總結---方法的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.