Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object as argument

 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic