0
Which of these are not legal identifiers. Select the four correct answers. a. 1alpha b. _abcd c. xy+abc d. transient e. acc
7 Antworten
+ 5
Which language?
In Java:
a. 1alpha = no, identifier can not begin with a numeric value
b. _abcd = yes
c. xy+abc = no, can not use the operator + within the identifier
d. transient = no transient is a reserved keyword
e. acc = yes
+ 4
@luka
Exactly why I asked what language
@Tony
In every language that is taught here at SL beginning an identifier with an underscore _ is legal.
It may not be the convention, but it is legal. (When it comes to PHP I'm of course considering the first character after the $ as it is the actual identifier the $ just signifies that it is a variable)
+ 4
@Tony
The question itself is incorrect. Especially considering there isn't a language provided. Just because someone asks a question providing multiple choices and tells you that 4 of them are correct or incorrect does not mean that it is true, which in this case it is not.
+ 2
@ChaoticDawg
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html
yes it legal , but in his case , he needs 4 illegal , we can't just drop acc can't we !?
while the rest 3 are guaranteed false.
+ 1
1alpha = illegal number before alpha ,
_abcd = illegal because start with non alpha ,
xy+abc = illegal variable can't contain "+" ,
transient = illegal because a keyword ,
acc = legal
Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "quot;, or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not "quot; or "_". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted.
Subsequent characters may be letters, digits, dollar signs, or underscore characters. Conventions (and common sense) apply to this rule as well. When choosing a name for your variables, use full words instead of cryptic abbreviations. Doing so will make your code easier to read and understand. In many cases it will also make your code self-documenting; fields named cadence, speed, and gear, for example, are much more intuitive than abbreviated versions, such as s, c, and g. Also keep in mind that the name you choose must not be a keyword or reserved word.
If the name you choose consists of only one word, spell that word in all lowercase letters. If it consists of more than one word, capitalize the first letter of each subsequent word. The names gearRatio and currentGear are prime examples of this convention. If your variable stores a constant value, such as static final int NUM_GEARS = 6, the convention changes slightly, capitalizing every letter and separating subsequent words with the underscore character. By convention, the underscore character is never used elsewhere.
+ 1
@ChaoticDawg : LOL , ok ok , it just a variable , let's find other topic ,
I said it's okay using underscore , but , preferably not for some cases it might considered as white or blank space and can't be called to (based on the app Dev site too).
0
If this is challenge for Sololearners you can post this in the Quiz Factory.