This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic doubt - How to create methods in Java?

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
void takeMoney(double value){
totalMoney = totalMoney - value;
}



Why is there attribute into curly braces? I already saw the Object class...
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"totalMoney" is a variable defined outside of this method, and this method is just reducing the value of "totalMoney" by the amount of "value" (the method's parameter).

Does that answer your question? I'm not sure I understand what you're asking.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) void is the return type of the method

2) takeMoney is the method name

3) value is the method argument of type double

4) Inside the two curly braces lives the method body

Take a look at this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic