Currently, in our area()
function we expect only the width and length of a rectangle. What if we could modify our function to also calculate the area of a rhombus? Well, we could add another argument shape
to our function in the following manner.
However, we could also keep our default functionality, wherein we don't pass the shape argument and the calculation is done for rectangle by default.
In the snippet above, we have assigned rectangle
as a default argument to shape
. Now when we call area()
, if we don't pass the shape, rectangle
will be used by default.