Java MCQ: What is encapsulation in Java?
a) Hiding the internal state and requiring all interaction to be performed through methods
b) Inheriting methods from a superclass
c) Overriding methods in a subclass
d) Converting one data type to another
Answer:
a) Hiding the internal state and requiring all interaction to be performed through methods
Explanation:
Encapsulation in Java is the technique of bundling data (fields) and methods that operate on that data into a single unit, typically a class. It involves hiding the internal state of an object and requiring all interaction to be performed through methods.
Understanding encapsulation is crucial for creating well-structured and maintainable code, ensuring data integrity and security.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html