Java Reference
In-Depth Information
This concludes the discussion of scope and the overview of different types of variables. You now
know how to declare instance variables (member variables or fields), class (static) variables, and final
variables, and are aware that variables are defined within a specific scope or context, which deter-
mines how they can be accessed.
The next section turns your attention to the other big part of classes: behavior as defined through
methods. Just as with variables, there are different types of methods, but many of the aspects you
learned here will return.
defining Behavior: methods
Recall once more the simple class outline as follows. A class contains a block of variable definitions
(data) and methods (behavior), like so:
class CLASSNAME {
// VARIABLE DEFINITIONS
// METHOD DEFINITIONS
}
Or, to be more specific:
class CLASSNAME {
// FINAL CLASS VARIABLE DEFINITIONS
// CLASS VARIABLE DEFINITIONS
// FINAL INSTANCE VARIABLE DEFINITIONS
// INSTANCE VARIABLE DEFINITIONS
// METHOD DEFINITIONS
}
This section discusses in full the concept of class behavior, as defined through its methods.
Specifically, you will see:
Instance methods: Methods that are accessible by objects.
Class methods: Methods that are not bound to an object but instead belong to the class as
such, that is, to the blueprint of the object.
Constructors : A special method that governs how a class is instantiated; you have already
read about this method.
The main method: A special method definition that can be used to run your application.
Finally, you will also learn about argument passing . You have seen how methods can take argument
variables to use within the method's body. The way variables are passed to methods can be a little
bit daunting in Java at first—and can introduce subtle bugs when you're not aware—so it makes
sense to learn about this in a separate section.
instance methods
Just as with instance variables, an instance method (or a member method) is a method that's acces-
sible only through objects belonging to that class—meaning that they can be accessed only through
an initialized object.
 
Search WWH ::




Custom Search