What Is Encapsulation In Java?
Please any one tell me what is Encapsulation and what is difference between abstraction and Encapsulation? Thanks in advance
3 Answers - Sort by: Date | Rating
If you have been sick, you would have had medicines for sure. One of the tablets that you would have received is a capsule. I hope you would have seen it.
Now this kind of tablet, is a bit different from the others. From the outside its just a cap, and it hides everything that is contained within. But what lies inside may be 2 or 3 or more powders loosely arranged and packed within.
An object is something similar. It is created with the immense power of a class. While the composition of the class could be anything (as compared to the capsule), one may not know what is contained when you create the object handle
as in
A obj = new A();
you may say obj here is like the capsule to all those who want to consume it in their programs.
So, with this object one can use its inherent power.
Thus this concept of hiding away its true power is known as Encapsulation.
Hope this helps.
Now this kind of tablet, is a bit different from the others. From the outside its just a cap, and it hides everything that is contained within. But what lies inside may be 2 or 3 or more powders loosely arranged and packed within.
An object is something similar. It is created with the immense power of a class. While the composition of the class could be anything (as compared to the capsule), one may not know what is contained when you create the object handle
as in
A obj = new A();
you may say obj here is like the capsule to all those who want to consume it in their programs.
So, with this object one can use its inherent power.
Thus this concept of hiding away its true power is known as Encapsulation.
Hope this helps.
0
0
Guest
answered 8 months ago
Encapsulation is hiding of implementation details.Let me tell you an example for your second question : Consider a house without walls,Is it safe - No,it isnt.For safety and protection,we built walls on both sides(encapsulation is there).But,now the house is surrounded by only walls,what is the use?? So,you keep a door,thus making the house usable(Abstraction+Encapsulation).Abstraction is extracting essential properties.
0
0
Guest
answered 5 months ago
- How Can I Use Dmp File In Java?
- Can You Write A Program Called InheritanceTest.java To Support An Inheritance Hierarchy For Class Point–Square–Cube?
- Why We Use This Method In Java?
- Why Java Not Supports Multiple Inheritence?
- A Java Program To Get Sports Marks In Student Package And Print Total Marks Of Student?
- The Project Aims To Implement A JAVA Parser? 1- Classes And Functions 2- Arithmetic/logic Expressions 3- If Statement
- How To Get Java On My Lg 260?
- Write A Java Program To Store A Number Find If It Is Positive Or A Negative Number If Positive Print I Am The First?
- How To Update The Sim 3 Expansion?
- What Is An Attribute In Java?
- Do I Have To Write A Main Method In Every Class I Create?
- What How The Step For Make Library Management?
- In Which Process We Can Start Java?
- Define The Concept Of Java Byte Code?
- How To Run Remote Method Invocation In More Machine?
- How To Run Java Remote Method Invocation In More Machine?
- How To Make A Java Program That Will Ask The User To Input A Number And Display All The Even Number And The Sum Of All Even Numbers Based On The Inputted/ Given Numbers?
- Is A Static Variable An Instance?
- What Does Literati-on Mean?
- What Is Abstract Class In Details?
- What Is Meant By Remote Method Invocation In Java?
- What Is Meant By Servlet In Java?
- What Is Latest Technologies In Java?
- Write A Program Using Do…..while Loop To Calculate And Print The First M Fibonacci Numbers?
- What Is The Difference Between Reference &instance Variable?
- What Does Encapsulation Mean?
- What Is Meant By Encapsulation In C++?
- Are Encapsulation And Data Abstration The Same Or Not In C++ Language?
- What Is The Difference Between Aggregation, Abstraction And Encapsulation?
- Distinguish Between Data Encapsulation And Data Abstraction?
- What Is The Concept Of Overloading, Overriding, Encapsulation, Abstraction With Code In C++ And C#?
- What Is Java?
- What Was The Former Name For Java?

New Comment - Comments are editable for 5 min.