• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Don't need to keep a reference

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.....



In preceding code why you don't need keep reference to instance of class (new Foo().go()).In other words the main() method needs to create the instance only so that
main() method can invoke one of the instance's methods.
 
Marshal
Posts: 74702
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct. You have answered your own question. That is shorthand for. . . and you never use f again.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the ccontrl flow.
1.The main method is called .
2.The "new Foo()" creates an object of type Foo().
3.The method is called on the newly made Foo object via ".go()".
4.The go method executes completely.
5.Control returned to main method .
6.The semi colon is encountered ";" ,the object that you created is available for garbage collection.
7."main" method terminates
8.All well that ends well
HTH
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhijit Rai wrote:
6.The semi colon is encountered ";" ,the object that you created is available for garbage collection.



I can't tell if you're just speaking figuratively, or if you'e really thinking of your code as being interpreted one symbol at a time like this at runtime. It doesn't work that way at all, of course; the end-of-statement symbol is used by the compiler to understand your intent, but it has no runtime representation; there's no semicolon "instruction."
 
Abhijit Rai
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ernest rightly pointed out that there is no semi colon instruction .My description was intended to help figure out what exactly is happening logically .I have erred on the technical part though .For better understanding of the language I would suggest that you go through any good Java book ,find them at find here - list of beginers java books.
HTH
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic