Friday, July 20, 2018

methods - Is it possible to declare default argument in Java in String?




Is it possible to use default argument in the method with String. The code is shown below:




public void test(String name="exampleText") {
}


The code above generate error. Is it possible to correct it?


Answer



No, the way you would normally do this is overload the method like so:



public void test()
{

test("exampleText");
}

public void test(String name)
{

}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...