Forums.Sureshkumar.net : A Perfect Place to Share Knowledge         Blogs     Games    Magazines    

"Sharing knowledge does not lessen your store, often it gets you more. Sharing plays a key role in relationships and bonding, happens in small steps and is assisted through community membership."

Go Back   SURESHKUMAR.NET FORUMS > TECHNICAL DISCUSSIONS > JAVA Technologies
Register FAQ Members List Calendar Games Blogs Search Today's Posts Mark Forums Read

   

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 07-02-07, 07:03 PM   #1 (permalink)
Member
 
Join Date: Jan 2007
Age: 24
Posts: 31
Thanks: 23
Thanked 0 Times in 0 Posts
Thanks: 23
Thanked 0 Times in 0 Posts
Rep Power: 2 suganyak is on a distinguished road
Smile Doubt in Object creation

Hi friends ...
I am new to java so pls clear my doubt

How many objects are created in the following piece of code?
Myclasses class1, class2, class3;
c1 = new Myclasses ();
c3 = new Myclasses ();

Thanks
Suganya
suganyak is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-02-07, 07:05 PM   #2 (permalink)
Member
 
Join Date: Jul 2006
Posts: 67
Thanks: 11
Thanked 43 Times in 29 Posts
Thanks: 11
Thanked 43 Times in 29 Posts
Rep Power: 8 surekhav is just really nice surekhav is just really nice surekhav is just really nice surekhav is just really nice surekhav is just really nice surekhav is just really nice
Re: Doubt in Object creation

Hi Suganya,

Only 2 objects are created,
class1 and class3.
The reference c2 is only declared and not initialized.
So only two objects are created
__________________
Regards
Surekha
surekhav is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to surekhav For This Useful Post:
suganyak (07-02-07)
Old 07-02-07, 07:50 PM   #3 (permalink)
Member
 
avadhoot.dharmadhikari's Avatar
 
Join Date: Aug 2006
Location: Parli-V
Age: 24
Posts: 77
Thanks: 24
Thanked 9 Times in 8 Posts
Thanks: 24
Thanked 9 Times in 8 Posts
Rep Power: 5 avadhoot.dharmadhikari has a spectacular aura about avadhoot.dharmadhikari has a spectacular aura about avadhoot.dharmadhikari has a spectacular aura about
Re: Doubt in Object creation

Whenever you define int a,b,c; so we call a,b,c as variable this is datatypes it's mangae some memory on heap but initially it's define in heap as default value.that like as in java whenever you not use new keywords objects are not created means not get memory.we can only define reference variable.
In your ex
Myclasses class1, class2, class3;
c1 = new Myclasses ();
c3 = new Myclasses ();

here you create three reference variable class1, class2, class3;
which refer to MyClasses and create only two objects i.e.
c1 = new Myclasses ();
c3 = new Myclasses ();
i hope you understand.
__________________
Thanks & Regards
Avadhoot S Dharmadhikari
Hyderabad
avadhoot.dharmadhikari is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to avadhoot.dharmadhikari For This Useful Post:
t_mohan (08-02-07)
Old 11-02-07, 09:34 AM   #4 (permalink)
Junior Member
 
Join Date: Dec 2006
Posts: 20
Thanks: 0
Thanked 2 Times in 2 Posts
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 2 sureshkumar.t is on a distinguished road
Re: Doubt in Object creation

hi Friends

Object creation has three phases 1.declaration 2.instantiation 3.intialization.

Myclasses class1, class2, class3; this is declaration here we are reffering Myclasses objects with class1,class2 ans class3.

c1 = new Myclasses ();
c3 = new Myclasses ();
The new instantiate the object means it allocates some memory to Myclasses Object.
After that Myclasses constructer intaia;izes that object.

so, only two objects created there.

Thanks & regards,
SureshKumar
sureshkumar.t is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to sureshkumar.t For This Useful Post:
t_mohan (12-02-07)
Old 12-02-07, 03:15 PM   #5 (permalink)
Junior Member
 
kris_121's Avatar
 
Join Date: Feb 2007
Age: 26
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2 kris_121 is on a distinguished road
Re: Doubt in Object creation

Hi Suganya,

Myclasses class1, class2, class3;
When the above line of code is executed, the Java Virtual Machine(JVM) will create three reference variables class1, class2 and class3, but the objects are not created at this point i.e., the memory for the objects of type Myclasses is not allocated in JVM's memory.
c1 = new Myclasses ();
c3 = new Myclasses ();
When the above two lines are executed, two objects of type Myclasses are created in the JVM's memory.

Regards,
Kris
kris_121 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 15-02-07, 03:23 AM   #6 (permalink)
Member
 
Join Date: Aug 2006
Age: 25
Posts: 90
Thanks: 1
Thanked 10 Times in 7 Posts
Thanks: 1
Thanked 10 Times in 7 Posts
Rep Power: 3 rk_ramakrishnamca is on a distinguished road
Re: Doubt in Object creation

Hi Suganyak,
Fine, The code you are given as follows:
Myclasses class1, class2, class3;
c1 = new Myclasses ();
c3 = new Myclasses ();

I dont know you either may or maynot observing the one point here. What is that is, there is discrimination between the Reference variables and the objects. From the abow code, class1, class2, class3 are the reference variables, then if you want to create the objects such as c1 and c3
you must given the code as follows:
Myclasses c1 = new Myclasses ();
Myclasses c3 = new Myclasses (); otherwise the java compiler(javac) rises an error,suchas c1 and c3 are the undefined variables in Myclasses.

so, Finally there is no question of creating the objects in your given code.

Thank you,


If i commited any mistake. please correct me.
rk_ramakrishnamca is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
QTP 8.2 Tips & Tricks slinkanand Testing Tools & QA 12 13-11-08 05:08 PM
Some QTP Faqs, Useful........ kiran2710 Testing Tools & QA 4 24-10-08 01:18 AM
java JSP naga JAVA Technologies 4 21-08-06 05:03 PM
What’s the difference between thesr shilpa VB / ASP.NET Technologies 5 08-03-06 12:09 PM
JAVA collection naga JAVA Technologies 0 21-02-06 06:01 AM


All times are GMT +6.5. The time now is 02:15 PM.





Search Engine Optimization by vBSEO 3.1.0