This chapter reviews method parameters and local variables, as well as method overloading and method signature.
Method overloading means two or more methods have the same name but have different parameter lists: either a different number of parameters or different types of parameters. When a method is called, the corresponding method is invoked by matching the arguments in the call to the parameter lists of the methods. The name together with the number and types of a method's parameter list is called the signature of a method. The return type itself is not part of the signature of a method.
4. Parameters are Seen by their Own Method, Only
Answer:
Instance variables are used to store the state of an object. They hold values for as long as the object exists.
Parameters are Seen by their Own Method, Only
The formal parameters of a method can be seen only by the statements of their own method. This means that if a method tries to use a parameter of some other method, the compiler will find a syntax error.
Here is the CheckingAccount
class again, this time with a new definition of the toString()
method
public class CheckingAccount { private String accountNumber; private String accountHolder; private int balance; . . . . public void processDeposit( int amount ) { balance = balance + amount ; } // modified toString() method public String toString() { return "Account: " + accountNumber + "\tName: " + accountHolder + "\tBalance: " + amount ; } } |
Question 4:
Is this toString()
method correct?