Encapsulation.
Encapsulation is a concept that protects data. (data hiding), then we use (encapsulation) to protect the data in (method and variable).
GETTERS AND SETTERS. (Data in Out)
1.Get
2.Set
Ex : Class Human {
private int id;
private String name;
private int age;
}
Class Runprogramme {
public static void main(String[] args) {
Human h = new Human
h.id = 20038493058
h1.name = "Tharusha"
h2.age = "20"
✸ Reference variable name = new objectclass ();
Reference variable name ;
Variable name , method / variable ;
Variable name = values.
Class Hierachy ,
1. Object
2. Class
3. Method
4. Variable
Object Oriented Programming - Java ( OOP )
✸Protected (private) variable getters and setters are used to access and is called (Encapsulation).
✸Set and get methods should be public. (data protection) has been done so it can be accessed.
D.M.T. Dasanayaka
Software Engineer
Java Development.
Comments
Post a Comment