go to previous page   go to home page   go to next page

Answer:

Yes, that last statement will change the balance of account1.

You might not want to allow such undisciplined changes. Ideally, only writing a check or making a deposit should change the balance.

This is where the private access modifier is useful.


Method Definition

Now that we have a test program, we can add methods to the class one-by-one, testing each method as it is added. Recall the three methods from the requirements:

Remember the syntax for method definition:

returnType methodName ( parameterList )
{
  statementList
}

The first line in the above is called the signature of a method definition. It does not have to be all on one line. The returnType is the data type that the method returns. It will be one of the primitive data types, or a class. The methodName is an identifier picked by the programmer. It can be any identifier except for reserved words or identifiers already in use. The parameterList is a list of parameters and their data types. If there are no parameters, the parameter list is omitted, (but the two parentheses must be there).


QUESTION 10:

(Review: ) What is returnType when a method does not return a value?