007 - Classes and Objects Flashcards
In a class declaration. The __________ (the area between the braces) contains all the code that provides for the life cycle of the objects created from the class:
class body
The class body contains: A. \_\_\_\_\_\_\_\_\_\_ for initializing new objects B. \_\_\_\_\_\_\_\_\_\_ for the fields that provide the state of the class and its objects C. \_\_\_\_\_\_\_\_\_\_ to implement the behavior of the class and its objects.
constructors
declarations
methods
class declarations can include these components, in order:
- _________ such as public, private.
- _________, with the initial letter capitalized.
- __________ preceded by the keyword extends.
- _________ preceded by the keyword implements.
- __________, surrounded by braces, {}.
- Modifiers
- The class name
- the class’s parent (superclass), if any. (A class can only extend (subclass) one parent.)
- A comma-separated list of interfaces implemented by the class, if any (A class can implement more than one interface.)
- The class body
There are several kinds of variables:
- Member variables in a class: __________.
- Variables in a method or block of code: __________.
- Variables in method declarations: __________.
fields
local variables
parameters
Field declarations are composed of three components, in order:
- __________, such as public or private.
- The field’s __________.
- The field’s __________.
- Zero or more modifiers
- type
- name
__________ used lets you control what other classes have access to a member field.
The first (left-most) modifier
__________—the field is accessible from all classes.
public modifier
__________ —the field is accessible only within its own class.
private modifier
In the spirit of encapsulation, it is common to make fields __________.
private
All variables must have a __________.
You can use __________ such as int, float, boolean, etc.
Or you can use __________, such as strings, arrays, or objects.
type
primitive types
reference types
the same naming rules and conventions are used for method and class names, except that
the first letter of a class name \_\_\_\_\_\_\_\_\_\_, the first (or only) word in a method name \_\_\_\_\_\_\_\_\_\_.
should be capitalized
should be a verb
The only required elements of a method declaration are: the method's \_\_\_\_\_\_\_\_\_\_, the method's \_\_\_\_\_\_\_\_\_\_, a pair of \_\_\_\_\_\_\_\_\_\_, and a \_\_\_\_\_\_\_\_\_\_.
return type
name
parentheses, ()
body between braces, {}
More generally, method declarations have six components, in order:
1__________such as public, private.
- __________ the data type of the value returned by the method, or void.
- __________ the rules for fields apply to methods as well, convention is a little different.
- __________ in parenthesis.
- __________ to be discussed later.
- __________, enclosed between braces.
- Modifiers
- The return type
- The method name
- The parameter list: a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.
- An exception list
- The method body: the method’s code, including the declaration of local variables, goes here.
Two of the components of a method declaration comprise the method signature: __________ and __________.
the method’s name
the parameter types
Definition: Two of the components of a method declaration comprise __________: the method’s name and the parameter types.
the method signature
By convention, method names should be __________ or __________, followed by adjectives, nouns, etc.
In multi-word names, the first letter of each of the second and following words __________.
a verb in lowercase or a
multi-word name that begins with a verb in lowercase
should be capitalized
Typically, a method has a unique name within its class. However, a method might have the same name as other methods due to __________.
method overloading
Java can distinguish between methods with different __________.
method signatures