Question

In: Computer Science

Why can reference parameters not be optional parameters? What are the conditions for generating ambiguous methods?

  • Why can reference parameters not be optional parameters?
  • What are the conditions for generating ambiguous methods?

Solutions

Expert Solution

1)

Reference Parameter

The ref keyword is utilized to pass a argument as a kind of perspective or reference. This implies when estimation of that parameter is changed in the technique, it gets reflected in the calling. A argument that is passed utilizing a ref keyword must be instated in the calling before it is passed to the called method

Optional parameter

Method with a optional parameter can be called with just a portion of its parameter determined. Each optional parameter has a default an incentive as a feature of its definition. In the event that no argument is sent for as parameter, then the default value is utilized.

2)

Ambiguity may happen when the overload function, optional arguments is used. Ambiguity is showed in situations where the compiler doesn't know which of the overload function to call.

for example, lets consider a method that have 2 function with same name that is a method overloading.

Int samp(int p,int q = 5, int r = 9)

{

                return p+q+r;

}

Int samp(int p, double q = 5.9, double r = 8.2)

{

                return (int)(p + q +r);

}

In this example if we call the method samp with one argument ie, p .

such that,

int a;

a = samp(8);

Then the compiler will generate a error message


Related Solutions

C# Discussion question Why can reference parameters not be optional parameters? What are the conditions for...
C# Discussion question Why can reference parameters not be optional parameters? What are the conditions for generating ambiguous methods? What arethe differences between mandatory parameters and optional parameters? Explain the use of arguments in reference parameters, output parameters, and parameter arrays. Expalin overloading.
What are returns to scale? Under what conditions (that is, for what values of the parameters...
What are returns to scale? Under what conditions (that is, for what values of the parameters a and b) does the Cobb-Douglas production function,q = KaLb, exhibit constant and increasing returns to scale? (Hint: See Solved Problem 6.3.)
Why is the maturity of some bonds ambiguous? What does it mean to say that a...
Why is the maturity of some bonds ambiguous? What does it mean to say that a bond has a value less than one for its relative yield differential?what might account for the differential?
Why is S. aureus such a virulent organism? What conditions can it cause? What about the...
Why is S. aureus such a virulent organism? What conditions can it cause? What about the organism can lead to so many different kinds of infection/disease?
What is a good reference for Why prostatitis and infection happens? The reference need to be...
What is a good reference for Why prostatitis and infection happens? The reference need to be after 2016.
Why can the atmosphere on the synoptic scale be considered an incompressible fluid? Under what conditions...
Why can the atmosphere on the synoptic scale be considered an incompressible fluid? Under what conditions is this true?
What role does a Firewall play in an organization. What are the parameters that can be...
What role does a Firewall play in an organization. What are the parameters that can be utilized with Access Control Lists?
1) What permutation group is pentagon D5 a subgroup of ?why? 2) What is a generating...
1) What permutation group is pentagon D5 a subgroup of ?why? 2) What is a generating set of pentagon D5? Why? Is it a minimal generating set?Why or why not? 3) What is not a generating set of pentagon D5? Why?
a. Why can steam distillation be an effective method to separate 2 compounds? b. What conditions...
a. Why can steam distillation be an effective method to separate 2 compounds? b. What conditions must be met for steam distillation to be useful?
Compare the various methods for evaluating suppliers. Which are best for what conditions? What is important...
Compare the various methods for evaluating suppliers. Which are best for what conditions? What is important about the specific metrics
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT