Your SlideShare is downloading. ×
0
12   encapsulation
12   encapsulation
12   encapsulation
12   encapsulation
12   encapsulation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

12 encapsulation

294

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
294
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  1. Encapsulation<br />DhrubojyotiKayal<br />
  2. The attributes (data) and the behaviours (code) are encapsulated in to a single entity/container or class<br />Do not reveal the internals (fields) of the container to the external world<br />External world can use and change the internals using the exposed handles or behavior or methods<br />What is encapsulation?<br />
  3. Data Hiding<br />Essential to ensure that the state is not altered accidentally without applying the applicable constraints and rules<br />Make the data members private<br />provide getters and setters<br />Encapsulation in Java<br />
  4. Create a BankAccount class with a public double field balance with initial value of 100<br />Use a BankAccountTest class and from main method access this field to show the balance<br />Now write a new method withdraw which reduces balance by input amount<br />Now set the balance to 0<br />Withdraw 50 ? Now you have negative balance?<br />Change the class and apply rules to ensure no negative balance.<br />Use getters and setters<br />Exercise<br />
  5. Q&A<br />

×