aspose file tools*
The moose likes Beginning Java and the fly likes Objects as parameter inside the method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Objects as parameter inside the method." Watch "Objects as parameter inside the method." New topic
Author

Objects as parameter inside the method.

Abishek Kumar
Greenhorn

Joined: Oct 27, 2007
Posts: 5
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

Beginner topic. Moving.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

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?


    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40052
        
      28
    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

    Joined: Apr 20, 2006
    Posts: 3355

    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!
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Objects as parameter inside the method.