-2

I am learning java and in my learning material I found the following question:

You are creating an application that includes a number of methods. These methods will change the values of both primitive and reference variables passed in as arguments. Which statement best describes the effect that changes made in the method will have on the original variables? Choose the best option(s) from those listed below.

The question is whether the value reference type can be changed, and the answer is no. But could anyone help with showing a code which demonstrates this behavior? Thank you

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
harry
  • 25
  • 7
  • 1
    See http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value . – RealSkeptic Jan 05 '17 at 08:55
  • "These methods will change the values of both primitive and reference variables passed in as arguments" You simply can't do this in Java, because it is *always* pass-by-value. – Andy Turner Jan 05 '17 at 09:00

1 Answers1

0

reference type cant be changed. Java is a pass by value language. This means when you invoke a method ,such as Person p = new Person(); foo(p); You are pass a copy of reference p. So you cant change reference type,but you could change the value indicated by the reference.

mrz
  • 71
  • 3