A

Admin • 831K Points
Coach

Q. How many objects will be created?
String a = new String("Examveda");
String b = new String("Examveda");
String c = "Examveda";
String d = "Examveda";

  • (A) 4
  • (B) 3
  • (C) 2
  • (D) None of this
  • Correct Answer - Option(B)
  • Views: 38
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
Object will be created each time whenever we use new keyword. So, 2 object will be created simply for the first two line and matter is with remaining two bottom line. String c="examveda" creates an object and store it in String pool, next time when we are writing String d="examveda" it will first check in String pool whether object already exists or not. Since, it is existing, no new object will be created. Hence reference "d" points to existing object "examveda". So ultimately 3 object will be created at the end.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.