English

Explain the process of Initializing a String in Java.

Advertisements

Question

Explain the process of Initializing a String in Java.

Explain
Advertisements

Solution

In Java, String declaration is the process of declaring a reference variable of the String class. A String is declared by writing the class name String followed by a valid variable name and a semicolon. This declaration creates a reference variable that can refer to a String object, but no String value is assigned at this stage.

  1. Write the class name String.
  2. Specify a valid variable name.
  3. End the declaration with a semicolon (;).

Syntax:

String variableName;

Example:

String name; 
In the above example, String is the class name, and name is the reference variable declared to refer to a String object.
shaalaa.com
  Is there an error in this question or solution?
Chapter 5: Primitive Values, Wrapper Classes, Types and Casting - EXERCISE [Page 112]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 5 Primitive Values, Wrapper Classes, Types and Casting
EXERCISE | Q 9. (ii) | Page 112
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×