Explain the process of declaring a String in Java.
Advertisements
Question
Explain the process of declaring 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.
- Write the class name
String. - Specify a valid variable name.
- 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?
