134k views
2 votes
Why can’t Java methods change parameters of primitive type? Java methods can have no actual impact on parameters of any type. Parameters of primitive type are considered by Java methods to be local variables. Parameters of primitive type are immutable. Java methods cannot accept parameters of primitive type.

User Mitchellt
by
5.3k points

1 Answer

1 vote

Answer:

Parameters of primitive type are considered by Java methods to be local variables.

Step-by-step explanation:

The parameters in JAVA are passed by value only. This means a parameter is considered to be local and a copy of the value is created used locally.

So if you change parameters of the primitive type so the value you change is local to the method. This implies that a copy of the parameter is made and the changes made on this copy will not affect the argument's value. In a nut shell, the parameters of primitive type are considered by Java methods to be local variables.

User Artur Kasprzak
by
4.9k points