Is the following declaration correct?

int answer;

A good answer might be:

Yes-- assuming that  answer  is a correct name for a variable.

Names for Variables

The programmer (you) picks a name for each variable in a program. There are several things in programs (including variables) that need to be named. Such a programmer-picked name is called an identifier. Here are the rules for choosing an identifier:

  • Use only the characters 'a' through 'z', 'A' through 'Z', '0' through '9', character '_', and character '$'.
    • A name can not contain the space character.
  • Do not start with a digit.
  • A name can be any length.
  • Upper and lower case count as different characters.
    • So  SUM  and  Sum  are different names.
  • A name can not be a reserved word.
  • A name must not already be in use in this part of the program.

A reserved word is a word which has a predefined meaning in Java. For example int, double, true, and import are reserved words. Rather than worry about the complete list of reserved words, just remember to avoid using words that you know already mean something, and be prepared to make a change if you accidentally use one you didn't know.

QUESTION 6:

Which of the following variable declarations are correct?

long good-by ;

short shrift = 0;

double bubble = 0, toil= 9, trouble = 8

byte the bullet ;

int  double;

char thisMustBeTooLong ;

int 8ball;

Click Here after you have answered the question