一、Java学习中的总结---方法的使用

 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)

方法抽象:方法抽象是通过方法的使用和实现分离来实现的,方法抽象的概念可以应用与程序的开发过程中。可以使用‘分治’策略,也称之为逐步求精,将大问题分解成子问题,子问题又可以分解成更小、更容易处理的问题。

原文地址:https://www.cnblogs.com/chentexi/p/9456709.html