GeeCON Prague 2014*
The moose likes Java in General and the fly likes Way of Calling a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Way of Calling a method" Watch "Way of Calling a method" New topic
Author

Way of Calling a method

Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
Hi All,
objName.methodcall(Param pObj(){})
Where objName is Object Name
methodcall is Method Name
Param pObj() is a parameter passed as object refence.
There are two(opening and closing)curly braces after pObj(){}
Just let me know whether this way of calling any method is correct.
Thanks..
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

I'm not sure what you're asking. What you've written above is not correct Java syntax, in any context; but I'm not sure if it's supposed to be, or if it's supposed to be pseudocode.
If this was in the beginners's forum, I'd explain something about calling methods in general. But since this is the intermediate forum, I'll assume you're asking a harder question, and I just don't understand what it is. Can you restate the question in a different way?


[Jess in Action][AskingGoodQuestions]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
This is the normal way of calling a method:
objName.methodcall(Param pObj)
When you call a method you normally just pass in a reference to an object of type Param. The acutal code would look like:
1)Param pObj = new Param(); //create object
objName.methodcall(pObj); //pass object to method
The only reason you would have parenthesis () included would be to indicate that you were calling method instead of naming a variable which is a reference. If you are saying that you intend to call a method and that method will return an object of type Param you might use that syntax, but that is much less common than the syntax above.
2) objName.methodcall(this.diffmethod()); //diffmethod returns an object of type Param
The only reason that you would ever have curly braces in the parameter of a method call would be if you are declaring an anonymous class and instantiating it at the same time, and that instance is the parameter into the methodcall.
3) objName.methodcall(new someInterface(){public void someAction(SomeParam e){//do something}});
Is that what you were asking?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
Hi All,
Thanks u all for replying to my post.Specially Cindy, U answered my question.Actually ur 3rd part is my answer and to which I was looking forward.
I was not sure whether we can give curly braces in a method call.
Thanks again to all of u.
If there can be any more suggestions or posts on this ..please go ahead as I really want to know much more about this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Way of Calling a method