This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How many objects created? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "How many objects created?" Watch "How many objects created?" New topic
Author

How many objects created?

Shubhada Nandarshi
Ranch Hand

Joined: Jun 10, 2005
Posts: 59
1. StringBuffer s1 = new StringBuffer("abc");

2. StringBuffer s2 = s1;

3. StringBuffer s3 = new StringBuffer("abc");

How many objects are created ?
1. 0

2. 1

3. 2

4. 3

Answer : 4


How??
Because,
s1,s2 & s3 are references to the object not the objects themself.The s2 will refer to the object created by the s1,then how 3 objects are created? the ans should be 3rd option 2.

Plz explain me if I am wrong.


Shubhada
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
How is this question different from the other discussion in the same forum?
Shubhada Nandarshi
Ranch Hand

Joined: Jun 10, 2005
Posts: 59
sorry Timmy ,
I didn't see the other discussion forum.As I got confused I asked in forum.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How many objects created?
 
Similar Threads
RHE question - String buffer
Object creation??
How many objects created?
number of objects created
how many objects are created?