Multiple choice technology programming languages

What is the correct way to declare and initialize a string object, "start", whose value - "Welcome to Java Programming" - can be shared?

  1. String start = new String("Welcome to Java Programming");

  2. String start[] = "Welcome to Java Programming";

  3. String start = "Welcome to Java Programming";

  4. none

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

String literals in Java are automatically interned and shared from the string pool. Using new String() creates a separate object. The array syntax in B is incorrect for a single String.

AI explanation

String literals in Java are stored in the string constant pool, so writing String start = "Welcome to Java Programming"; lets the JVM reuse (share) an existing identical literal instead of creating a new object. Using new String(...) explicitly forces a new heap object that bypasses the pool, so it would not be shared, and declaring start[] creates an array type rather than a single String object.