Does Java support default parameter values?

后端 未结 25 2185
清歌不尽
清歌不尽 2020-11-22 07:07

I came across some Java code that had the following structure:

public MyParameterizedFunction(String param1, int param2)
{
    this(param1, param2, false);
}         


        
25条回答
  •  半阙折子戏
    2020-11-22 07:39

    NO, But we have alternative in the form of function overloading.

    called when no parameter passed

    void operation(){
    
    int a = 0;
    int b = 0;
    
    } 
    

    called when "a" parameter was passed

    void operation(int a){
    
    int b = 0;
    //code
    
    } 
    

    called when parameter b passed

    void operation(int a , int b){
    //code
    } 
    

提交回复
热议问题