Ask Question
11 January, 17:40

Which of the following method signatures correctly specifies an array as a return type?

a) private array testMethod (int x)

b) private int[ ] testMethod (int x)

c) private double[5] testMethod (int x)

d) private double testMethod[ ] (int x)

e) can't tell from this code

+4
Answers (1)
  1. 11 January, 20:56
    0
    private int[ ] testMethod (int x)

    Explanation:

    Before going to the reason first understand the syntax of declare the function.

    Syntax:

    Access_modifier return_type name (argument_1, argument_2, ...);

    Access_modifier is used for making the restriction to access the values.

    it is public, private and protected.

    Return_type: it is used to define return type of the function.

    it can be int, float, double.

    In the question:

    Option 1: private array testMethod (int x)

    it is not valid because array is not valid return type.

    Option 2: private int[ ] testMethod (int x)

    int[ ] denotes the integer array. so, the function return the integer array.

    Option 3: private double[5] testMethod (int x)

    it is not valid because double[5] is not valid return type. we cannot enter the size of the array.

    if we replace double[5] to double[ ], then it valid and the function return double type array.

    Option 4: private double testMethod[ ] (int x)

    it return type is double. So, it return the decimal value but not array.

    Therefore, the correct option is (b).
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Which of the following method signatures correctly specifies an array as a return type? a) private array testMethod (int x) b) private int[ ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers