This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Object as argument Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object as argument" Watch "Object as argument" New topic
Author

Object as argument

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
Hi,

I have one small doubt. I have confuse in sending the object as method's argument. Is possible to give one simple example coding for this.

In the method's argument what are all the things we can pass?

for example: If we are sending the object of class 'A' as the method's argument, we can say that we are sending all the variables and methods in that class 'A'. I think I am missing something or mess up something.

Please provide one example coding on how we can pass the class' object as the argument. And also if possible what are the things happening inside the coding will be very helpful.

Thanks in advance.
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi,

When you send an object as an argument, you send an reference to the
object (in memory).

When you send object A to object B, B have access to A's public interface,
ie. it's visible methods and varaibles.

A small example in java/pseodu code. You have to supply code for some
of the classes.


/Svend Rost
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
you actually pass reference variable of an object not the object itself. Example, if you have an ArrayList of Pets it contains object references of Animals. You can fill up your Arraylist through a method that takes in Object References as an argument.


I'm a Hood Ornament
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Object as argument