• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method invocation  RSS feed

 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Pardon me,but I have a silly question to ask.
Is there any difference in invoking a method from a reference variable,and invoking it explicitly by the object itself,i.e new ClassName().methodName();

Thanks...
 
Sathiesh Kumar Vs
Ranch Hand
Posts: 31
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A a = new A();
a.m1();

new A().m1();

Both are same in terms of method invocation. Only difference is in the first case you still have the reference of the created object but in the second you don't have.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!