Answers to Self-Test Questions
1. The following are all legal variable names:
rate1, TimeLimit, numberOfWindows
TimeLimit
is a poor choice, however, since it violates the normal convention that variables should start with a lowercase letter. A better choice would betimeLimit. 1stPlayer
is illegal because it starts with a digit.myprogram.java
is illegal because it contains an illegal character, the dot. Finally,long
is illegal as a variable because it is a keyword.2. Yes, a Java program can have two different variables with the names
aVariable
andavariable
, since they use different capitalization and so are different identifiers in Java. However, it is not a good idea to use identifiers that differ only in the way they are capitalized.
Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.