File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
Bartender

Joined: Aug 20, 2001
Posts: 1817

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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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]
 
GeeCON Prague 2014
 
subject: How many objects & ref