06. Encapsulation

06. Encapsulation

Java Concept

Introduction

This concept is very important among the most commonly used. The meaning of encapsulation is to make sure that ‘sensitive’ data is hidden from users. to achieve this you must :

  • Declare class variables/attributes as private
  • provide a public get and set method to access and update the value of a private variable.

How do we use the above method and parameter passing? etc. is what this article is talking about.

What is the set and get?

  • private variables can be accessed only by people of the same class.
  • However, it is possible to access them if we provide a public get and set method.
  • The get method returns the variable value, and the set method sets the value.
  • Syntax for both is that they start with either get or set followed by the name of the variable, with the first letter in upper case.

Code example :

Conclusion

“If we use encapsulation, we must create get method and set method. And Flexible the programmer can change one part of the code without affecting other parts. Due to the increased security of data.”

GOOD LUCK!!!!!!

References

https://www.w3schools.com/java/java_encapsulation.asp


要查看或添加评论,请登录

Ishan Nikeshala Nawarathna的更多文章

  • Interface

    Interface

    I talk about interface. Introduction.

  • 07. Abstraction

    07. Abstraction

    Java Concept Introduction This concept is very important. In this article, we discuss how to create a class and write…

    2 条评论
  • 05.Java Overloading

    05.Java Overloading

    Java concept Introduction The overloading method is a powerful tool that empowers developers to create more concise…

  • 04. Polymorphism

    04. Polymorphism

    java concept Introduction java polymorphism is one of the essential object-oriented programming allowing objects of…

    4 条评论
  • 03. Method Overriding

    03. Method Overriding

    java concepts Introduction In the world of object-oriented programming, Java stands out as a popular language that…

社区洞察

其他会员也浏览了