Review OOP Concept
Class - > is like the BLUEPRINT to make something.
When you make an OBJECT from a CLASS, it is called an INSTANCE of a Class.
1. Name - > like a name you give an object - > Identifier
2. Attributes - > like specific characteristics for the object - > Variables
3. Behaviours - > like actions the object can perform - > Instance Methods
UML – Unified Modeling Language
Because in Java everything is wrapped in a class, it can get very confusing! We can use UML to show the structure of a Class.
Name of Class
± Attributes/Variables : Data-Type
± Behaviour/Methods (param name: param data-type, etc …): Return-Type
± - > plus or minus represent the ACCESS MODIFIERS, which are:
+ - > public - - > private
Encapsulation and Access Modifiers
We use public and private to add security to VARIABLES and METHODS. This is called ENCAPSULATION.
public - > means a VARIABLE or METHOD can be used INSIDE & OUTSIDE the class
private - > means a VARIABLE or METHOD can only be used INSIDE the class
Why are the variables private and methods public?
Because we want to protect variables from being accessed directly; so they can’t be changed or used incorrectly. To GET a value from a variable or to GIVE a variable a value we write public methods to do this.
For example we could have changed the setMarks method from the Student Class to prevent users from entering an incorrect value: