SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Methods And Behaviors
Exercise:
Exercises
Question:15 | ISBN:9781285096261 | Edition: 4

Question

Given the following method definition, what would be a valid call? The variable
someIntValue is defined as an int.
public static int GetData(out int aValue, ref int bValue)
a. someIntValue = GetData(aValue, bValue);
b. someIntValue = GetData(out aValue, ref bValue);
c. someIntValue = GetData(out, ref);
d. someIntValue = GetData(int out aValue, int ref bValue);
e. GetData(out aValue, ref bValue);

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

The correct answer is b. someIntValue = GetData(out aValue, ref bValue);

Explanation:

Consider the method definiton:

public static int GetData(out int aValue, ref int bValue)

  • This GetData method accepts the reference parameters.
  • It should contain the the keyword "out" and "ref".
  •  The first choice " someIntValue = GetData(aValue, bValue); " does not have the reference keyword "out" and "ref" parameters.  ITs only accept the interger variables. So, option (a) is NOT correct answer.
  • The second choice " someIntValue = GetData(out aValue, ref bValue); " is the valid call. It accepts reference parameters. So, the correct answer is (b).
  • The third choice " someIntValue = GetData(out, ref); " is missing the variables. Only reference keywords are provided. It is invalid call method. So, the option (c) is NOT correct answer.
  • The fourth choice " someIntValue = GetData(int out aValue, int ref bValue); "  is invalid statement.  So the option (d) is incorrect answer.
  • The final choice " GetData(out aValue, ref bValue); " is missig the storing variable " someIntValue ". So, the option (e) is incorrect.

So, the correct answer is b. someIntValue = GetData(out aValue, ref bValue);

0 0

Discussions

Post the discussion to improve the above solution.