Quiz 2 Flashcards
Function definition
A set of instructions that perform a task
Method Definition
A set of instructions that are associated with a task
Two components to a method?
Method heading (access modifiers, return types, name and parameters)
The block (pair of curly brackets containing the code that fulfils the methods responsibility)
Java constructor?
A special method that enables an object to initialise itself when it is created
Why use access modifiers
A public interface
Private details
That way many people can work on a project with no problem provided they have agreed on public interfaces
Encapsulation?
Hiding implementation details of an object from its clients
The encapsulation principle?
An object should be an encapsulated entity, providing an API. The user of an object should not be aware of the internal representation of state or details of algorithms.
Java encapsulation?
Binding of data and methods together into a single unit such that they are kept both safe from outside interference and misuse
How to achieve encapsulation in Java
By declaring the member variables of a class as private
Providing a public setter/getter methods to modify and view the variable values
Private member variables are only accessibly within the class
Only by using the getter methods the private members can be accessed outside the class
Benefits of encapsulation?
o Data hiding
o Code reusability
o Getter & setter methods
o Total control
o Flexibility & maintainability
o Ease of testing