Encapsulation in Java in Details Step by Step



OOPS concepts in Java

Java tutorials for beginners

Java basics concepts

Java Objects and Classes

What is Inheritance in Java?

What is Abstraction in Java?

What is Interface in Java?

What is Abstract Class in Java?

What is Polymorphism in Java?

What is Encapsulation in Java?

Java programming example

How Java Program Work?

Hello World in Java

Java basics for beginners



Encapsulation:


Encapsulation is the process of wrap the data and code into single unit. The variables of a class will be hidden from other classes, and can be accessed by methods of their current class.

Make encapsulation in following way.

1. Declare variables as private.
2. Declare public setter and getter methods to access or modify the value.


Example:

public class Employee {
        private int id;
        private String name;
        private int age;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
       } 
}

32 comments:

  1. Really very good article. the post has excellent tips which are very useful.


    laptop price

    ReplyDelete
  2. Excellent Post. Are you looking for Laptops for your training? Click here Laptop Price to select your idle Laptop in budget.

    ReplyDelete
  3. Learn Advanced Core Java Course in Delhi, Noida & Gurgaon with Lowest Fees. High Technologies Solutions is the Correct Place for Core Java Course. Call Now & Get Free Demo Classes- +91-9311002620, +91-11-40504400.
    More Info-https://www.htsindia.com/Courses/JAVA/core-Java-training-course-institute
    Core Java Course in Delhi, Noida & Gurgaon

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

    ReplyDelete
  5. I always enjoy reading quality articles by an individual who is obviously knowledgeable on their chosen subject. Ill be watching this post with much interest. Keep up the great work, I will be back..
    Dot Net Training Institute in Noida
    C C++ Training Institutes in Noida
    Java Training Institute in Noida

    ReplyDelete
  6. This will help them expand their technical brilliance and also have the edge over the competition.
    java training in navalur

    ReplyDelete
  7. Hi Your Blog is very nice!!

    Spark Infosys offers PHP training, Real Time PHP Training, PHP Online Training in Hyderabad by Experienced Professionals. We offer a PHP Project and Placements Assistance etc..

    ReplyDelete
  8. Wow!! Really a nice Article. Thank you so much for your efforts. Definitely, it will be helpful for others. I would like to follow your blog. Share more like this. Thanks Again.Java training in Mumbai

    ReplyDelete
  9. A great deal of valuable and informative guidance imparted by you. I am glad to discover this worthwhile information here. Continue sharing. Professional Web design services are provided by W3BMINDS- Website designer in Lucknow.
    Web development Company | Web design company

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

    ReplyDelete
  11. I am very happy when this blog post read because blog post written in good manner and write on good topic.
    Thanks for sharing valuable information
    Java Training Institute in Noida
    Android Training Institute in Noida
    Oracle Training Institutes in Noida


    ReplyDelete
  12. Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
    best java training in coimbatore
    php training in coimbatore

    ReplyDelete
  13. "Thank you for sharing such thing. I Hope that you will share these kind of knowledgeable things from next time the knowledge of programming language is must nowdays to get entry in Information technology. Thank you again.
    bigdata training in mohali data science training in Chandigarh dot net training in Chandigarh "

    ReplyDelete
  14. Thanks for such a great article here. I was searching for something like this for quite a long time and at last, I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.
    Selenium Training in Gurgaon

    ReplyDelete
  15. Thanks for Sharing such a great article here.
    AWS Training in Delhi

    ReplyDelete
  16. I am very happy when this blog post read because blog post written in good manner and write on good topic.
    Thanks for sharing valuable information
    Dot Net Training Institute in Noida
    Android Training Institute in Noida
    Java Training Institute in Noida


    ReplyDelete
  17. Hi Your Blog is very nice!!

    Spark Infosys offers PHP training, Real Time PHP Training, PHP Online Training in Hyderabad by Experienced Professionals. We offer a PHP Project and Placements Assistance etc..

    ReplyDelete
  18. Thanks for sharing this wonderful article. Your article is very interesting to read.
    Java Training Institutes in Mehrauli

    ReplyDelete

  19. Thanks for sharing this valuable information and we collected some information from this blog.
    Android Training in Noida

    ReplyDelete
  20. I like your blog. Thanks for Sharing the good post
    Java course in Delhi

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

    ReplyDelete
  22. Thanks for sharing such a great blog Keep posting.. 
    Android Training in Delhi

    ReplyDelete
  23. Nice Post! Thank you for sharing knowledge, it was very good post to update my knowledge and improve my skills. keep blogging.
    Best AngularJs Training in Pune

    ReplyDelete
  24. Really good article. Thanks for sharing this kind of devlopement articles with us. Politely see Devops Course in Bangalore once see the site to get depth of information in java.

    ReplyDelete
  25. most important and informative thing. Helps this generation in many ways. Lots of support keep going.
    AI Training in Bangalore

    AI Course in Bangalore

    ReplyDelete
  26. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition
    Java Training in Bangalore

    Java Course in Bangalore

    ReplyDelete