It's not a secret anymore!
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object as argument" Watch "Object as argument" New topic

Object as argument

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129

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

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
I agree. Here's the link:
subject: Object as argument
It's not a secret anymore!