Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String objects

 
rengarajan vaikuntam
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at this snippet:

String st = new String("JAVA");

How many objects are created and how many reference variables are created?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 Strings. 1 Reference variable.
 
rengarajan vaikuntam
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks corey
so if i have class called MyClass and if i say

MyClass mc = new MyClass();

Here also can i say 2 objects are created one with the keyword new and the other null and one reference variable mc.

thanx.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic