From the previous article I gave you a basic introduction about Object Oriented Programming. This article will gives you a clear picture on Encapsulation
Encapsulation is one of the four fundamental OOP concepts with inheritance, Polymorphism and Abstraction.It basically gives the the idea of bundling data and methods that work on that data within one unit.It is used to hide the internal representation of a state of an object from outside.So when executing a program it will make your code much safer.And this mechanism will be much more easier to use.
By using Encapsulation we can easily modify our code without breaking the code of others who use the same code.Also it enables the code to be,
- flexible
- maintainable
- extensible
Example :
class Person{
private int age;
private String name;
}
In here when using private key word it can only used inside the particular class. And this will not be visible to any other classes.
Hope to see you soon with another Object Oriented Programming Concept
Comments
Post a Comment