• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Primitive Data Type Arguments  RSS feed

 
Mohammad Mah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I am totally new to Java. I need someone to explain the concept below in a simpler way. I'd really appreciate it.

What is the purpose of this method?

Can you explain the flow of the int x=3; like where does the 3 go step by step? Thank you guys.

Passing Primitive Data Type Arguments (from oracle java tutorials)

Primitive arguments, such as an int or a double, are passed into methods by value. This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost. Here is an example:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of this method is to show that changing a method parameter doesn't change the caller.

On line 5, x becomes 3. It stays 3 for the whole program. On line 19, p becomes 10. However x and p are different because the values are being passed.
 
Mohammad Mah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much.

This post helped too:
http://www.coderanch.com/t/595750/java/java/Passing-Reference-Data-Type-Arguments#2908089
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!