Implement polymorphism and encapsulation; functions and classes
Filed under Barclays
Free read 3 of 3Bundle data and methods and hide the internals. Example: class BankAccount with a private balance and public deposit() and withdraw() that validate input, so outside code cannot set an invalid balance.
The question
Implement polymorphism and encapsulation in OOP, and discuss functions and classes. The language was not specified, so state your choice.
Approach
Bundle data and methods and hide the internals. Example: class BankAccount with a private balance and public deposit() and withdraw() that validate input, so outside code cannot set an invalid balance.
Compile-time: method overloading. Runtime: a base class Shape with area(), overridden in Circle and Rectangle; a Shape reference calls the right area() depending on the real object.
A function is a reusable block of logic. A class is a blueprint combining data (fields) and behaviour (methods); a method is a function bound to an object.
Create objects, call through the base type and show that private data cannot be changed directly. Mention the benefits: maintainability and extensibility.
Tips
- What they are testing: Whether you can write and explain basic OOP code, not just define terms.
- Common mistake: Giving definitions only, or demonstrating 'encapsulation' with public fields.
Related Barclays questions
Collected from public candidate posts and coding forums. Updated Nov 2026.