• 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

Whizlab question Query

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

WhizLab Question from Facebook



The code is in the attached image file

How many objects will be eligible for garbage collection after the execution of line 9 in the following code?
Choose one answer.
a. 8
b. 14
c. 15
d. 16


i think answer should be 16

am i wrong ??
IF yes,then why??
whiz.jpg
[Thumbnail for whiz.jpg]
Whiz Question code
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, it would 15. Insert a System.out.println(x) on line 9.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should be 15.
The first Object of type Double is created at Line 5
and then another 15 Objects of type Double are created in the nested loops from lines 6 to 8

So, there are 16 objects in total, variable x referring to the last Double object with value i+j=4+2=6.
variable a is a primitive, and not an Object.
So, you have 15 objects available for GC
reply
    Bookmark Topic Watch Topic
  • New Topic