180k views
3 votes
Which of the following lines correctly defines a String variable

A. String s = aplus;
B. s = "aplus";
C. String s = "aplus";
D. String = "aplus";
E. String;

User Boey
by
5.5k points

1 Answer

6 votes

Answer:

The answer to this question is given below in the explanation section.

Step-by-step explanation:

The correct answer to this question is C i.e. String s = "apluse";

The rule or syntax of declaring string in any programming language is given below:

String variable-name = "yourString";

For declaring string variable, first, you write "String" that is a keyword of a programming languages for declaring string variables, such as int before the variable name for declaring integer variable. Then, you need to write a meaningful name of the string as a variable. After string variable name, you need to put the equal operator and then write the string in double quotation("") marks and after that put the instruction terminator that is ";".

So, according to this syntax, option C is correct.

While other options are not correct because:

In option a, string is not encapsulated in double quotation. Option B does not have varaible type such as String and Option E does not have variable name and its value also. So, only option C is correct and all other except C are incorrect.

User Robert Crovella
by
5.4k points