Which of the following correctly declares a method that accepts one…
2024
Which of the following correctly declares a method that accepts one dimensional array of double as a parameter?
- A.
public void fun(double *arr[])
- B.
public void fun(double[] arr)
- C.
public void fun(arr double[])
- D.
public void fun(double arr)
- E.
Question not attempted
Attempted by 548 students.
Show answer & explanation
Correct answer: B
In Java, arrays are declared using the '[]' notation after the data type. For a one-dimensional array of doubles, the correct parameter declaration is 'double[] arr'.
Option A uses 'double *arr[]' which is C-style pointer syntax and is invalid in Java.
Option B uses 'double[] arr' which correctly declares a one-dimensional array of doubles as a method parameter.
Option C has incorrect syntax with 'arr double[]' - the variable name should come after the type.
Option D declares 'double arr' which is a single double variable, not an array.