Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many objects & ref

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the below pgm say:
How many reference variables are there?
How many objects are there?

O/P: 3 & 0



Consider this pgm and sat the same:



O/P: 4 & 4

Please explain how??
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the comments in the code explain it quite nicely. Is there anythign more specific that you have questions on?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know what "O/P" means, but I think you're giving those as the answers. In that case, the first one is wrong. I see three variables (as do you, of course) each being assigned a newly-created object, so there are 3, and not 0, objects. In the second problem, there are obviously 4 and 4, going by the traditional SCJP interpretation (of course, there are many more objects created during the execution of each of these programs, but we're playing by the rules.)

These kinds of questions -- i.e., "tricky test questions" -- really belong in the SCJP forum. I'm going to move this over there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic