Chapter 3-2 Flashcards
type variableName = value;
Where type is one of Java’s types (such as int or String), and variableName is the
name of the variable (such as x or name). The equal sign is used to assign values
to the variable.
Syntax
These unique names are called
Identifiers
The general rules for naming variables are:
- Names can contain letters, digits, underscores, and dollar signs
- Names must begin with a letter
- Names should start with a lowercase letter and it cannot contain
whitespace - Names can also begin with $ and _ (but we will not use it in this tutorial)
- Names are case sensitive (“myVar” and “myvar” are different variables)
- Reserved words (like Java keywords, such as int or boolean) cannot be
used as names
Kinds of Variables
- Local Variable
- Instance Variable
- Static Variable
____ variables are declared in methods, constructors, or blocks. _____variables are created when the method, constructor or block is entered
and the variable will be destroyed once it exits the method, constructor, or
block. Access modifiers cannot be used for _____
Local Variable
_____ variables are declared in a class, but outside a method, constructor or any block. _____ variables are created when an object is created with the use of the keyword ‘new’ and
destroyed when the object is destroyed. Access modifiers can be given for _____
Instance Variable
Static Variable
Class variables also known as _____ variables are declared with the static keyword in a class, but outside
a method, constructor or a block. _____ variables can be accessed by calling with the class name ClassName.VariableName.