Which of the following keywords is used to declare a variable as a constant in a Java program?
a. void
b. constant
c. final
d. literal
e. static
Java help please 2?
i think that the question pretty much makes it clear............. if not, here is the answer for the less able computer programmers: FINAL
Reply:a. void - is the keyword used to specify that no value is expected in the specification of a method
void setSize (double inputSize);
b. constant - is not a keyword in Java
c. final - as others have indicated, this is answer. I tell my students to remember that the value is being set for the final (and only) time. I also happen to believe that this is a rotten keyword to use for a constant, but no one asked me.
d. literal - not a keyword in Java
e. static - used to specify that there is only one instance of this "thing". Usually, each time than an object is created from a class, an entirely separate and new set of "things" (variables, methods, etc.) are created. Except for the items marked "static". A variable marked static only exists in one place and is shared across all the instances of any objects created. Constants (keyword final) that are static only exist in one place and don't take up memory space in all the instances of objects that are created. Like most powerful tools, static is easily abused and can cause problems that are very difficult to solve.
Likely more than you wanted to know, I'm sure.
John
Reply:c. final
Reply:e or a im not sure
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment