Ask Question
29 November, 16:29

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. 29 November, 16:58
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers