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

totally how many objects will be created?

 
varinder mahajan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the declaration of strings,
String s1="abc";
String s2="xyz";
String s3=new String("abcd");
totally how many objects will be created?
 
Deepak Bajoria
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres 3 strings created here
 
mahesh chandra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
totally 4 objects will be created

when you say String s1="abc"; it will create one string object in the string pool and s1 reference varible will be refering that,where as String s3=new String("abcd"); creates one string poll object and one string object and reference varible s3 will be refering the object created in the pool
so totally 4
 
Ronald Schild
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There will be 4 String objects after this code has run.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic