Multiple choice technology programming languages

String strA; String strB = new String("Cheese"); How many objects have been created in the above code snippet?

  1. 3

  2. 1

  3. 2

  4. 0

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Only one String object is created by 'new String("Cheese")'. The 'String strA;' declaration only creates a reference variable (null initially), not an object. In practice, this code would use a string literal instead, but technically only the 'new' keyword creates an object.