jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How many objects & ref Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How many objects & ref" Watch "How many objects & ref" New topic

How many objects & ref

Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
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

Joined: Aug 20, 2001
Posts: 1824

I think that the comments in the code explain it quite nicely. Is there anythign more specific that you have questions on?

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link: http://aspose.com/file-tools
subject: How many objects & ref
It's not a secret anymore!