Which fundamental object-oriented programming (OOP) concept bundles data fields and the methods that operate on that data into a single unit while restricting direct external access?
Answer and explanation
Correct answer: D. Encapsulation
- Step 1: Encapsulation wraps data attributes and methods inside classes.
- Step 2: By using private access modifiers and public getters/setters, it enforces information hiding and prevents unauthorized external manipulation of internal object state.
Answer
Encapsulation.
Why not the others: 'Polymorphism' allows objects of different classes to respond to the same interface; 'Inheritance' allows classes to derive attributes from parent classes; 'Dynamic binding' resolves method calls at runtime.
Practise more Python Programming, Data Structures, Algorithms, Networks and Cybersecurity.
Free questions with an explanation for every one, and full timed Saudi Secondary School Certificate mock tests.
More Python Programming, Data Structures, Algorithms, Networks and Cybersecurity questions
- What is the time complexity of searching for an element in an unsorted array of elements using linear search?
- What is the output of the following Python expression: `[x**2 for x in range(5) if x % 2 == 1]`?
- Which data structure operates on a Last-In, First-Out (LIFO) access principle?
- Which SQL clause is used to filter aggregated group records after a `GROUP BY` statement has been applied?
- What type of network topology connects all nodes to a central forwarding device such as a network switch?
- In cybersecurity, what type of malicious attack overwhelms a web server with massive volumes of traffic from multiple compromised sources to…