ENCAPSULATION
ENCAPSULATION
SAJEEL_UR_REHMAN DSAI-242102023
REHAN ISHFAQ DSAI-242102015
ASAD_UR_REHMAN DSAI-242102011
WHAT IS ENCAPSULATION ?
Modular Design
Encapsulation enables the creation of self-contained,
reusable component that can be easily integrated into
1 larger system.
Code Maintainability
Encapsulation makes it easier to modify the internal
implementation of an object without effecting the external
2 code that uses it.
Data Security
Encapsulation protects the internal state of an object,
3 ensuring data integrity and preventing unintended
modifications
PRINCIPAL OF ENCAPSULATION
DATA HIDING ABSTRACTION Modularity
• Encapsulation • It provides a • Encapsulation
hides the layer of promotes
internal abstraction, modular
implementatio allowing design, making
n details of an developers to it easier to
object, interact with maintain, test,
exposing only objects without and extend the
the necessary needing to codebase.
methods and understand
properties to their complex
BENEFITS OF ENCAPSULATION
Data Integrity Flexibility Maintainability
• Encapsulation • Changes to the • Encapsulation
ensures that an internal promotes code
object's internal implementation reuse, reduces
data is accessed of an object can debugging
and modified be made without efforts, and
only through the affecting the makes the
object's own code that uses it, codebase more
methods, as long as the readable and
maintaining data public interface manageable.
consistency and remains the
preventing same.
IMPLEMENTING ENCAPSULATION IN CODE
this.age=age;
this.height=(float)height;
return age;
}
CODE:
public float getHeight(){
return height;
}
}
public class Person {
public static void main(String[] args) {
Detail obj = new Detail();
obj.setAge(23);
obj.setHeight(4.12);
System.out.println("person's age is: "+obj.getAge());
System.out.println("person's height is:"+obj.getHeight());
}
}
OUTPUT:
ANY
QUESTIO
N
THANK
YOU