1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Java classes include…
Fields (attributes of an object or the class)
Methods (operations on an object or the class)
Static field values
Same for all methods
Non-static field value
each object has its own
What are instance variables
non-static fields in a class declaration
What are class variables
Static fields in a class declaration
Local variables
variables in the method or block
Class variables
static fields in a class declaration
Instance variables
Non-static field in a class declaration
Parameters
variables in a method declaration
What is a method
A parameterized block of code that may return a value
Static method
Can only access static fields and other static methods in the class
Can be called using class name. i.e. Math.pow(2,5)
Non-static method
May access non-static fields associated with the particular object
Must be associated with an object, e.g., t3.describ()
If no object is specified, “this” is implied
Methods are useful for…
Reusability
Readability
Modularity
Method Syntax
return_type methodName(param_list) {
statements;
return; // If needed
}
Basic variable scope
Usable from the point of declaration to the end of the enclosing block
“Special” Variable scopes
Parameters: accessible within the method body, can “hide” fields with the same name
For loop variable: accessible within heading and body
this
refers to…
the current object
Signature
the name and parameter types of a method/constructor