• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Objects as parameter inside the method.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beginner topic. Moving.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
     
    Marshal
    Posts: 76811
    366
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 3389
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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!
     
    Slime does not pay. Always keep your tiny ad dry.
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic