Saturday, July 17, 2021

Encapsulation

 


Encapsulation is one of the OOPs concepts in Java which protects the data members of the class. Java is by default encapsulated where we cannot declare a variable outside the class. Java language provides four access specifiers to achieve encapsulation.

Restricting the direct access and providing indirect access through public services called getters and setters methods, is called as encapsulation.

Hiding the internal state and requiring all interaction to be performed through an object's publicly exposed methods is known as Encapsulation.

How to achieve Encapsulation:

By using access modifiers we can achieve.

1. declare class variables as private.

2. define public getters and setters methods to access & update the value of a private variable.

Example code for Encapsulation:

https://github.com/SripriyaPKulkarni/OOPs-Encapsulation

Application of Encapsulation in Framework:

1. All the classes in a framework are an examples of Encapsulation.

2. All the data members declared in POM classes using @FindBy and initializing the data members using Constructor to utilize the data members in methods in test folder.

5 comments:

  1. Your words touch the heart. You write beautifully and have good expressing
    click for more

    ReplyDelete
  2. So for I used to comment anywhere /any blogs or videos now I do commenting ,,really it matter ,,thanks lot ,explaining in details,,,
    right here

    ReplyDelete
  3. 6. Well hello there! it was so fantastic to visit your blog and to read article. And I have
    a question for you. Have you ever done article blogging

    Read this post here

    ReplyDelete
  4. Thank you very much for writing such an interesting article on this topic. This has really made me think and I hope to read more. software development company

    ReplyDelete
  5. Thank you for taking the time to write such an informative post. Your blog is not only informative, but it is also very creative.
    web application development company

    ReplyDelete