Ask Question

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

+1
Answers (1)
  1. 1 October, 17:54
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers