Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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