Java MCQ: Which of the following is true about encapsulation in Java?
Answer:
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 is a fundamental concept in object-oriented programming (OOP) that helps to protect the internal state of an object from unauthorized access and modification.
Encapsulation also involves using access modifiers, such as private
, protected
, and public
, to control the visibility of class members. By restricting access to the internal state of an object, encapsulation helps to enforce data integrity and hide implementation details from the outside world.
Encapsulation is essential for creating well-structured and maintainable code, as it allows you to change the internal implementation of a class without affecting other parts of the program.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html