Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Communication between classes  (Read 985 times)
0 Members and 1 Guest are viewing this topic.
Offline draziw123

Junior Newbie




Java games rock!


« Posted 2004-02-17 01:09:49 »

Hello.  Im Developing a lemonade based game and i have a question.  How do you pass information through classes is basically it.  The first class handles the menus that occur between game days (what inventory do you want to purchse...type question) the second class handles the animation and the processing of the game day information.  I have a third class called inventoryItem.  This class is created for each inventory item to handle things like the number of that item, ect.
--> inventoryItem Hamburger = new inventoryItem();  //ex
 How can I pass the inventoryItem to the second class, make changes to it and then get those change back to the first class and visa versa?  (Im a c++ programmer and java is weird to me without the pass by value/reference stuff in c++)
Any help would greatly be aprreciated!
kul_th_las
Guest
« Reply #1 - Posted 2004-02-18 13:22:35 »

Everything in Java is pass-by-value, but the Java definition of pass-by-value is probably a bit different than the definition you're used to when it comes to objects.

I understand your confusion, but here's a nice little article covering the nuances of parameter passing in Java. It's going to sound a bit strange because, like I said, it is a bit different than the C world.

About half way through the article there's a section labeled "Pass by Value" that specifically addresses your question, but the whole artcile can be of use.
http://java.sun.com/docs/books/tutorial/java/javaOO/arguments.html

After you've read the article, this next part of my post is going to make more sense:

When you pass an object parameter into a method, you're really just passing an int (or maybe a long) that is the memory address to the object. So, when they say everything is pass-by-value, yet you can change an object within a method, they simply mean that you're passing the object reference by value. When the method exits, the same identifier name will still point to the same object in memory, even though the values of the fields in that object may have been altered by the method.

Welcome to Java, and the games community
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (77 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (119 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (125 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (178 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.076 seconds with 22 queries.