• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling a method using new object().method();  RSS feed

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I was wondering how an Instance of a class Is found when you call one of It's method using

new object().method();

Instead of

object dog=new object();

dog.method();

How Is It found without a reference variable to It's location ?
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a reference there, but it does not have a name.

'new Object()' is a statement, and evaluates to a reference of type Object. The reference has no name if you don't assign it to a variable, but its still there and you can call methods on it or pass it as a parameter to a method.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok! Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!