Converting Default Arguments Java Help

Converting Default Arguments

One extensively used feature of c++ that Java docs not support is default  unction arguments. For example, tile areal ) function shown in the following c++ program computes the area of a rectangle if called with two arguments, 01′ the area of a square if called with one argument.

As Connolly see, when are is called with ‘only one argument, the second default to zero. When this happens, the {unction simply uses the first argument for both the
length and the width of the rectangle. ‘ While convenient, default arguments are not, of course, necessary, In essence, default arguments are actually n shorthand form of (unction over London in which  one form of the function has a different number of parameters than the other.  to convert a c++ function that contains one or more default arguments into Java, simply center overloaded methods that handle each case, In this example, you need n version of  that takes two arguments and another that takes only one argument.  approach, here Is the preceding program rewritten for Java:

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 18, 2014 in Migrating from C+tto Java

Share the Story

About the Author

Back to Top