Java function parameter Default Value

Source: Internet
Author: User

Java function parameter Default Value

Today, you need to set the default value of Java function parameters and find that the method in other languages does not work.

Java only seems to be implemented through function overloading.

 

Function parameter Default Code Java code
  1. Public class parameterdefault {
  2. /**
  3. * @ Param ARGs
  4. */
  5. Public String getname (string givenname, string familyname ){
  6. Return givenname + "." + familyname;
  7. }
  8. Public String getname (string givenname ){
  9. Return getname (givenname, "xie ");
  10. }
  11. Public static void main (string [] ARGs ){
  12. // Todo auto-generated method stub
  13. Parameterdefault = new parameterdefault ();
  14. System. Out. println (parameterdefault. getname ("AAA "));
  15. System. Out. println (parameterdefault. getname ("AAA", "Liu "));
  16. }
  17. }

 

Running result code running result code
  1. AAA. Xie
  2. AAA. Liu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.