Tuesday, September 3, 2013

Encapsulation | how to achieve encapsulation in Java


Encapsulation:


Before moving into the concept and definition, first of all i would like to ask you one thing. Do you know about capsule (medicine)? Have you seen capsule .?

Everyone has the same answer for the above questions. that is YES

If you know a capsule , definitely you knew about encapsulation.

How a capsule will look like?

As every one knows that the medicine which is wrapped is the capsule.

How Capsule related to Encapsulation: 


Just like a capsule(which wraps up medicine) , wrapping up  the data is called Encapsulation in OOPS. Encapsulation is a mechanism of hiding the data 
( variables/methods ) from the external world.

In java a class is the best example of Encapsulation

How to achieve Encapsulation in Java:


In java, Encapsulation can be achieved by using access specifiers (especially private modifier). 

As we know a private access specifier specifies access with in the class (local access), the data can't be exposed to the other classes (in same application or different application).


Let me elaborate this with an example.

CapsulateData is the class with some variables as given below.



As accountNumber, accountName are private variables they can't be accessed outside the class.

If we try to do so, following will be the result.





Here as accountName and accountNumber are private fileds, we can't access them in other classes(not only variables , even private methods also).

From this, we can clearly understood that the data
 (accountName , accountNumber ) is hidden by the class from the outside world, which we consider to be encapsulation.




126 comments:

  1. Replies
    1. IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.

      IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.

      corporate training in chennai corporate training in chennai

      corporate training companies in india corporate training companies in india

      corporate training companies in chennai corporate training companies in chennai

      I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai

      Delete
  2. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand basic concepts. As a beginner in java programming your post help me a lot.Thanks for your informative article.java training in chennai | chennai's no.1 java training in chennai

    ReplyDelete
  3. perfect explanation about java programming .its very useful.thanks for your valuable information.top 10 java training institutes in chennai | java training in velachery

    ReplyDelete
  4. this post is very useful for everyone who learn java encapsulation in detail.
    thanks for this nice post.

    ReplyDelete
  5. nice blog. thanks for sharing valuable information. It’s really good.Any one looking software courses nareshit is the best offline and online software training institute in Hyderabad and Chennai.

    ReplyDelete
  6. Australia Best Tutor is one of the best Online Assignment Help providers at an affordable price. Here All Learners or Students are getting best quality assignment help with reference and styles formatting.

    Visit us for more Information

    Australia Best Tutor
    Sydney, NSW, Australia
    Call @ +61-730-407-305
    Live Chat @ https://www.australiabesttutor.com




    Our Services

    Online assignment help
    my assignment help Student
    Assignment help Student
    help with assignment Student
    Students instant assignment help
    Students Assignment help Services

    ReplyDelete
  7. Thank you very much for posting and sharing this great Blog And Good Information.carry on your posting.

    Best Red Hat training in Noida
    Red Hat Training Institute in Noida

    ReplyDelete
  8. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up Java online training Hyderabad

    ReplyDelete
  9. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Are you looking for the best Java training institute in Chennai?
    Come and learn with Aorta, the best java training institute in Chennai offering the best platform to learn and get the depth of Java
    java training in chennai
    java course in chennai

    ReplyDelete
  10. Each department of CAD have specific programmes which, while completed could provide you with a recognisable qualification that could assist you get a job in anything design enterprise which you would really like.

    AutoCAD training in Noida

    AutoCAD training institute in Noida


    Best AutoCAD training institute in Noida

    ReplyDelete
  11. 6-week summer course in Noida - 6 weeks The summer course plays a crucial role in shaping the career of young aspiring / informatics students. This training has been specifically introduced so that students can become familiar with current industrial culture and industrial needs. Webtrackker technology offers a 6-month training program for students / graduates that includes small and large projects.
    6-week summer course in Noida

    ReplyDelete
  12. Cloud Computing Training In Noida
    Webtrackker is IT based company in many countries. Webtrackker will provide you a real time projects based training on Cloud Computing. If you are looking for the Cloud computing training in Noida then you can join the webtrackker technology.
    Cloud Computing Training In Noida , Cloud Computing Training center In Noida , Cloud Computing Training institute In Noida ,

    Company Address:
    Webtrackker Technology
    C- 67, Sector- 63, Noida
    Email: info@webtrackker.com
    Website: www.webtrackker.com
    http://webtrackker.com/Cloud-Computing-Training-Institutes-In-Noida.php

    ReplyDelete
  13. Video editing course in Noida
    Video editing training institute in Noida- Webtrackker Technology is and IT Training institute providing the Video editing course in Noida, FCP, Final Cut Pro Training in Noida. For more call us- 8802820025.
    Video editing course in Noida
    best video editig course in noida
    best video edtitng institute in noida
    Company Address:
    Webtrackker Technology
    C- 67, Sector- 63, Noida
    Phone: 01204330760, 8802820025
    Email: info@webtrackker.com
    Website: http://webtrackker.com/Best-training-institute-Video-editing-FCP-course-in-Noida.php

    ReplyDelete
  14. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    Click here:
    angularjs6 Training in Chennai
    Click here:
    angularjs Training in online

    ReplyDelete
  15. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts
    Microsoft azure training in chennai
    Click here:
    Microsoft azure training in online
    Click here:
    Microsoft azure training in bangalore
    Click here:
    Microsoft azure training in pune

    ReplyDelete
  16. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 
    Blueprism training in velachery

    Blueprism training in marathahalli


    AWS Training in chennai

    ReplyDelete
  17. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Devops Training in Chennai

    Devops Training in Bangalore

    ReplyDelete

  18. Like different elements of India, numerous oil and spices usually cross into making food. This effects in substances getting caught to the partitions of the filter out.
    Visit here
    http://kitchenware.ml
    Best kitchen chimney installation and service
    Auto clean chimney sevice in Faridabad

    ReplyDelete
  19. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging.
    Sap Basis Online Training
    Sap Abap Online Training
    Sap Pp Online Training

    ReplyDelete
  20. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    best rpa training in chennai |
    rpa training in chennai |
    rpa training in bangalore
    rpa training in pune | rpa online training

    ReplyDelete
  21. I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
    java training in annanagar | java training in chennai

    java training in chennai | java training in electronic city

    ReplyDelete
  22. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
    Data Science training in Chennai | Data science training in bangalore
    Data science training in pune | Data science online training
    Data Science Interview questions and answers

    ReplyDelete
  23. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    iosh course in chennai

    ReplyDelete
  24. Thanks for sharing. I really liked your post, keep sharing!!

    CEH Training In Hyderbad

    ReplyDelete
  25. Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
    angularjs online training

    apache spark online training

    informatica mdm online training

    devops online training

    aws online training

    ReplyDelete

  26. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Matlab Training in Chennai | Best Matlab Training in Chennai
    AWS Training in Chennai | Best AWS Training in Chennai
    Devops Training in Chennai | Best Devops Training in Chennai

    ReplyDelete

  27. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Matlab Training in Chennai | Best Matlab Training in Chennai
    AWS Training in Chennai | Best AWS Training in Chennai
    Devops Training in Chennai | Best Devops Training in Chennai

    ReplyDelete
  28. You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete
  29. Mình đã tìm thấy các thông tin cần thiết ở đây, cảm ơn bạn. Mình cũng muốn giới thiệu về một Công ty dịch thuật uy tín - Công ty dịch thuật miền trung - MIDtrans có trụ sở chính chính tại địa chỉ 02 Hoàng Diệu, TP Đồng Hới, tỉnh Quảng Bình có Giấy phép kinh doanh số 3101023866 cấp ngày 9/12/2016 là đơn vị chuyên cung cấp dịch vụ dịch thuật, phiên dịch dành các cá nhân. Hệ thống thương hiệu và các Công ty dịch thuật con trực thuộc: công ty dịch thuật hcm - dịch thuật sài gòn 247 , địa chỉ 47 Điện Biên Phủ, Phường Đakao, Quận 1 TP HCM, dịch thuật buôn mê thuột, đăk lăk : địa chỉ 100 , Lê lợi, TP Buôn Mê Thuột là nhà cung ứng dịch vụ dịch thuật uy tín hàng đầu tại Đăk Lăk; vietnam translate : dịch vụ dịch thuật cho người nước ngoài có nhu cầu, giao diện tiếng Anh dễ sử dụng; dịch thuật công chứng gò vấp : nhà cung ứng dịch vụ dịch vụ dịch thuật phiên dịch hàng đầu tại Quận Bình Thạnh, TP HCM; dịch thuật đà nẵng : Địa chỉ 54 Đinh Tiên Hoàng, Quận Hải Châu, TP Đà Nẵng chuyên cung cấp dịch vụ dịch thuật công chứng, dịch thuật chuyên ngành tại Đà Nẵng; dịch thuật hà nội midtrans : địa chỉ 101 Láng Hạ, Đống Đa, Hà Nội là nhà cung ứng dịch vụ biên dịch, phiên dịch chuyên nghiệp tại địa bàn Hà Nội. Chúng tôi chuyên cung cấp các dịch vụ biên dịch và phiên dịch, dịch thuật công chứng chất lượng cao hơn 50 ngôn ngữ khác nhau như tiếng Anh, Nhật, Hàn, Trung, Pháp, Đức, Nga, Tây Ban Nha, Bồ Đào Nha, Ý, Ba Lan, Phần Lan, Thái Lan, Hà Lan, Rumani, Lào, Campuchia, Philippin, Indonesia, La Tinh, Thụy Điển, Malaysia, Thổ Nhĩ Kỳ..vv... Dịch thuật MIDtrans tự hào với đội ngũ lãnh đạo với niềm đam mê, khát khao vươn tầm cao trong lĩnh vực dịch thuật, đội ngũ nhân sự cống hiến và luôn sẵn sàng cháy hết mình. Chúng tôi phục vụ từ sự tậm tâm và cố gắng từ trái tim những người dịch giả.Tự hào là công ty cung cấp dịch thuật chuyên ngành hàng đầu với các đối tác lớn tại Việt nam trong các chuyên ngành hẹp như: y dược (bao gồm bệnh lý), xây dựng (kiến trúc), hóa chất, thủy nhiệt điện, ngân hàng, tài chính, kế toán. Các dự án đã triển khai của Công ty dịch thuật chuyên nghiệp MIDtrans đều được Khách hàng đánh giá cao và đạt được sự tín nhiệm về chất lượng biên phiên dịch đặc biệt đối với dịch hồ sơ thầu , dịch thuật tài liệu tài chính ngân hàng, dịch thuật tài liệu y khoa đa ngữ chuyên sâu. Đó là kết quả của một hệ thống quản lý chất lượng dịch thuật chuyên nghiệp, những tâm huyết và kinh nghiệm biên phiên dịch nhiều năm của đội ngũ dịch giả của chúng tôi. Hotline: 0947688883. email: info@dichthuatmientrung.com.vn . Các bạn ghé thăm site ủng hộ nhé. Cám ơn nhiều

    ReplyDelete

  30. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.

    Machine Learning Training in Chennai | Machine Learning Training Institute in Chennai
    Devops Training in Chennai | Devops Training Institute in Chennai
    Data Science Training in Chennai | Data Science Course in Chennai

    ReplyDelete
  31. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete
  32. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Python Training in Electronic City

    ReplyDelete
  33. I feel very grateful that I read this. It is very helpful and very informative and I Python training in pune really learned a lot from it.

    ReplyDelete
  34. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
    AI course malaysia

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. Excellent Blog! I would like to thank for the efforts you have made in writing this post. It is very informative. I wanted to thank you for sharing this information!! Artificial Intelligence Course

    ReplyDelete
  37. Attend The Analytics Course in Bangalore From ExcelR. Practical Analytics Course in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Analytics Course in Bangalore.
    ExcelR Analytics Course in Bangalore

    ReplyDelete
  38. Appreciating the persistence you put into your blog and detailed information you provide.

    Data science Course Training in Chennai |Best Data Science Training Institute in Chennai

    ReplyDelete
  39. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks; from every one of us.
    Aws training chennai | AWS course in chennai
    Rpa training in chennai | RPA training course chennai
    oracle training chennai | oracle training in chennai

    ReplyDelete
  40. Nice blog,I understood the topic very clearly,And want to study more like this.
    Data Scientist Course

    ReplyDelete

  41. Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well I really get amazed to read this. It's really good.
    I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!.
    mobile phone repair in Fredericksburg
    iphone repair in Fredericksburg
    cell phone repair in Fredericksburg
    phone repair in Fredericksburg
    tablet repair in Fredericksburg
    mobile phone repair in Fredericksburg
    mobile phone repair Fredericksburg
    iphone repair Fredericksburg
    cell phone repair Fredericksburg
    phone repair Fredericksburg


    ReplyDelete
  42. Really awesome blog!!! I finally found a great post here.I really enjoyed reading this article. Thanks for sharing valuable information.Data Science Course
    Data Science Course in Marathahalli
    Data Science Course Training in Bangalore

    ReplyDelete
  43. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
    Data Science Course

    ReplyDelete
  44. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression

    ReplyDelete
  45. Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article..Thanks for sharing this info,it is very helpful.
    Salesforce Training in Chennai

    Salesforce Online Training in Chennai

    Salesforce Training in Bangalore

    Salesforce Training in Hyderabad

    Salesforce training in ameerpet

    Salesforce Training in Pune

    Salesforce Online Training

    Salesforce Training

    ReplyDelete
  46. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression
    data science interview questions

    ReplyDelete
  47. Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Simple Linear Regression
    Correlation vs covariance
    data science interview questions
    KNN Algorithm
    Logistic Regression explained

    ReplyDelete
  48. I like your post. Everyone should do read this blog. Because this blog is important for all now I will share this post. Thank you so much for share with us.
    DevOps Training in Hyderabad
    DevOps Course in Hyderabad

    ReplyDelete
  49. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area. data science training in Hyderabad

    ReplyDelete
  50. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    Data science Training in hyderabad

    ReplyDelete
  51. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data science course

    ReplyDelete
  52. Attend The Course in Data Analytics From ExcelR. Practical Course in Data Analytics Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Course in Data Analytics.
    Course in Data Analytics

    ReplyDelete
  53. Attend The Data Analyst Course From ExcelR. Practical Data Analyst Course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analyst Course.
    Data Analyst Course

    ReplyDelete
  54. Thanks for posting the best information and the blog is very helpful.Data science course in Faridabad

    ReplyDelete
  55. Thanks for posting the best information and the blog is very helpful.data science interview questions and answers

    ReplyDelete
  56. Truly mind blowing blog went amazed with the subject they have developed the content. These kind of posts really helpful to gain the knowledge of unknown things which surely triggers to motivate and learn the new innovative contents. Hope you deliver the similar successive contents forthcoming as well.

    data science in bangalore

    ReplyDelete
  57. Wonderful blog found to be very impressive to come across such an awesome blog. I should really appreciate the blogger for the efforts they have put in to develop such an amazing content for all the curious readers who are very keen of being updated across every corner. Ultimately, this is an awesome experience for the readers. Anyways, thanks a lot and keep sharing the content in future too.

    data science institute in bangalore

    ReplyDelete
  58. Stupendous blog huge applause to the blogger and hoping you to come up with such an extraordinary content in future. Surely, this post will inspire many aspirants who are very keen in gaining the knowledge. Expecting many more contents with lot more curiosity further.

    data science certification in bhilai

    ReplyDelete
  59. Extraordinary blog filled with an amazing content which no one has touched this subject before. Thanking the blogger for all the terrific efforts put in to develop such an awesome content. Expecting to deliver similar content further too and keep sharing as always.

    data science training

    ReplyDelete
  60. My friend mentioned to me your blog, so I thought I’d read it for myself. Very interesting insights, will be back for more!
    data scientist training and placement in hyderabad

    ReplyDelete