my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Ways to invoke a method of an java object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Ways to invoke a method of an java object?" Watch "Ways to invoke a method of an java object?" New topic
Author

Ways to invoke a method of an java object?

M.Ravi
Greenhorn

Joined: Dec 12, 2001
Posts: 7
Can anyone tell me how many ways r there to invoke a method met() in Object A from another Object B?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Assuming that A.met() is visible from B, I can think of at least 3 ways:
1. directly - A a = new A(); a.met();
2. indirectly through another object, say C, which has a method that invokes A.met();
3. via the Reflection API.
Junilu

Junilu - [How to Ask Questions] [How to Answer Questions]
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Or if the method is static, A.met();
M.Ravi
Greenhorn

Joined: Dec 12, 2001
Posts: 7
My thinking is 3 ways of invocation:
1) One is by composition. Object B instantiating Object A inside
its method & invoking met().
2) Next is Class B extending Class A and thereby directly invoking met() with its object
3) Third is Object B invoking met() of Object A by remote invocation using the stub of Object A.
This is my thought. Correct me if i am wrong. Tell me if any other ways r there to invoke.
-MR
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
M.Ravi
Please see http://www.javaranch.com/name.jsp - a period (dot) in your account name is not the same as a space.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ways to invoke a method of an java object?
 
Similar Threads
invoking method within same EJB
application scope in servlet
Doubt in EL Question
How to invoke a method without arguments using Reflection
memory map of objects