Is the following declaration correct?

int answer;

Answer:

Yes— as long as the name  answer  has not already been used.

Names for Variables

The programmer picks a name for each variable in a program. In addition to variables, other things in programs may be given names. Such a name is called an identifier. Here are the rules for choosing an identifier:

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.

As a matter of programming style, a name for a variable usually starts with a lower case letter. A word that is part of the name starts with an uppercase letter, unless it is at the start of the name. For example, payAmount and grandTotal. These conventions are not required by syntax, but are useful to follow since they makes programs more readable.

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;