Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ways to invoke a method of an java object?

 
M.Ravi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me how many ways r there to invoke a method met() in Object A from another Object B?
 
Junilu Lacar
Bartender
Pie
Posts: 7272
44
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if the method is static, A.met();
 
M.Ravi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M.Ravi
Please see http://www.javaranch.com/name.jsp - a period (dot) in your account name is not the same as a space.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic