Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects as parameter inside the method.

 
Abishek Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one give me brief details about passing object as a parameter in the methods.
I am trying to understand the concept from books and online, but would appreciate if any one can give me just brief explanation.

For example:

public void method1(Object1 object1){
...
...
}

What is the concept behind passing object as parameter?

Thanks
 
Maneesh Godbole
Saloon Keeper
Posts: 11185
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beginner topic. Moving.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abishek Kumar wrote:
What is the concept behind passing object as parameter?

Thanks


Hi Abhishek,

Welcome to Ranch. The benefit/concept behind passing an Object as a parameter are:

  • Object serves as a container in which you can put many bits and pieces inside. The callers would just need to deal with one single item/argument and NOT many.
  • You can achieve Pass By Reference.


  • Does that help?
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 50239
    79
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Raghavan Muthu wrote: . . .[/list]
  • You can achieve Pass By Reference.
  • No you can't. You can pass the value of a reference, but as the link you quoted says, you can't implement pass-by-reference in Java.
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:
    Raghavan Muthu wrote: . . .[/list]
  • You can achieve Pass By Reference.
  • No you can't. You can pass the value of a reference, but as the link you quoted says, you can't implement pass-by-reference in Java.


    Yes. You are right CR . I meant to say, you can achieve and NOT implement.

    In a way you pass the object (reference) [Yes indeed it is 'pass by value' ], you can get the 'pass by reference' effects. Otherwise, you can't!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic