Encapsulation:
A collection of similar type of data & methods are protective in a single class with required access modifiers, so that can be saved from unauthorized access. The encapsulation is nothing but wrapping up of data together into a single unit and hiding selective properties and methods.
In java encapsulation class methods are declared with private access modifier and accessed by using of the setter () and getter () methods.
Note: String has only getter method properties so we can’t use setter( ) method for String variables. Because String is immutable.
Example: Capsule is the best example.
Use of encapsulation:
By using of setter and getter methods only we can be made read-only or write-only.
The class can have total control over the date and provide security.
Interview Questions:
What do you know about encapsulation?
What is the use of encapsulation class?
How can we access encapsulation class methods?
What is the real time example for encapsulation?
How to use setter() method to String variables?
1 comments:
Thanks for posting. Keep sharing. oracle adf online training
oracle rac online training
EmoticonEmoticon