Java OCA OCP Practice Question 1180

Question

Which of the following data types can be modified after they are passed to a method as an argument?

  • A. int[]
  • B. String
  • C. long
  • D. boolean


A.

Note

Option B is incorrect because String values are immutable and cannot be modified.

Options C and D are also incorrect since variables are passed by value, not reference, in Java.

Option A is the correct answer.

The contents of an array can be modified when passed to a method, since a copy of the reference to the object is passed.

The method can change the first element of a non-empty array.




PreviousNext

Related