• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

will the given code create an object at the time of execution

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Product
{ void fact(int p)
{ int i,f=1;
for(i=1;i<=p;i++)
f=f*i;
System.out.println("the answer is " +f);
}
}Will this snippet create an object at the time of execution?


 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

princy raja wrote:class Product
{ void fact(int p)
{ int i,f=1;
for(i=1;i<=p;i++)
f=f*i;
System.out.println("the answer is " +f);
}
}Will this snippet create an object at the time of execution?


What is the answer for the above question?
Please give me the answer....




Well, in order to discuss "time of execution", you actually need execution. So, assuming that the main thread creates a Product object to do the factorial, then yes. To confirm, you need to show us the code for the main thread.

Henry
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
Yes, I can see an object it will create at run-time, and it is not a Product instance.
By the way, a factorial method is a function which can beneficially be declared static. It is a 1368 in the most dubious and inaccurate classification of methods known to modern science, it usually comes out as a 1368. And the Product object is not actually necessary to run the code you showed.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't forget the String objects that get created...
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:Don't forget the String objects that get created...

Yes, that was what I saw.
 
reply
    Bookmark Topic Watch Topic
  • New Topic