Lecture 17 Objectives
At the end of today's class you should
KNOW:
- That encapsulation involves separating a module's implementation
details from its API
- That a method belongs in the class that contains the data the method is operating on
- That access modifiers provide a mechanism for controlling access
to fields and methods
- That the way for an object in one class to access data defined as private in another class is through a public method
BE ABLE TO:
- Choose the appropriate class for a method definition
- Choose the appropriate access modifier for a field or method
Sample Exam Question:
Add a deposit()
method to the BankingService class we developed.
deposit()
consumes an account number and an amount to deposit
and adds the amount to the balance in the account. The method returns the
new account balance. Use principles of encapsulation in designing your new method.