0% found this document useful (0 votes)
25 views

Encapsulation

Uploaded by

Nada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Encapsulation

Uploaded by

Nada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Encapsulation

AGENDA

01 Modifiers . 02 Encapsulation .

03 Examples .
01
Modifiers
They are words that you can add when defining new things (either
class , a variable , a function , eltc .. ) to specify how to access them .
There are two types of modifiers in Java:
1. access modifiers .

2. 2. non-access modifiers.
Non-access modifier :

Static Abstract
We don’t need to create an object to It is used to create an abstract
call the variable or function . class or function .

Final
Variable values can’t be changed .

Methods can’t be overridden .

Classes can’t be inherited


Search

- Search for other non access


modifiers .
- What is the effect of static
on variables , functions , and
classes ?

Create now

- Main class (Employee) .


- Class (Engineer).
- Class (leader).
02
Encapsulation
Why Encapsulation?
What is the encapsulation ?

It is a method that can be followed to


hide the basic data in the class . And
making other classes able to handle
these data only through functions
created by the main programmer of
the class .
The concept of the setter
and Getter functions :

setName : getName :
The goal is to give a The goal is to get the
value of the variable . value of the variable .
• The link is in the chat
Examples
Example1 -- Rectangle Example2 -- Date
1. Length (float) 1. Day (int)
2. Width (float) 2. Month (int)
3. -------------------- 3. Year (int)
4. - Rectangle() 4. -------------------
5. - Rectangle(length,width) 5. - Date(day, month, year)
6. - get && setLength() 6. - get && setDay()
7. - get && setWidth() 7. - get && setMonth()
8. - getArea() 8. - get && setYear()
9. - setDate(day,month,year)
Why Encapsulation?

1. It is provide you the control over


the data .
2. You can read only or write only
or read and write .
THANKS
Any questions?

You might also like