Java Reference
In-Depth Information
myString = myErrorMsg.getErrorMsg ();
(1) public String getErrorMsg () {...}
On the other hand, this call to getErrorMsg will always perform the method that
accepts one integer parameter and returns a String result:
myString = myErrorMsg.getErrorMsg (msgCode);
(2) public String getErrorMsg (int msgCode) {...}
The Java compiler will automatically match up the particulars of the method
invocation (in CALLER) with the particulars of the method (in ErrorMsg ), and
make sure the proper method is executed.
T ERMS TO R EVIEW
Let's review some of the object-oriented concepts just discussed and how you can
understand them from a Java perspective.
Methods: Methods are the functions that a class can perform. Performing a
method is similar to calling a function, or sending a message (to an object).
Method signatures: The method signatures of a class are the view it presents to
external programs. A class can have many public methods. Each method can be
further qualified by its method name, arguments, return type, and scope (e.g.,
public, protected, private). This combination of unique method name, argu-
ment profile, and return value is sometimes referred to as an interface in OO
design terms. Note that the term interface is formally reserved for a specific
construct in the Java language.
Method overloading: A class can define a method and then create more than
one signature for this method. These unique interfaces are distinguished by
their input parameters and return type.
E XERCISES : C LASSES , O BJECTS , AND M ETHODS
It's useful to use the keyboard and—as a good piano teacher might say—let your
fingers teach your mind. You'll experiment with some of the sample classes pre-
sented so far.
 
Search WWH ::




Custom Search