Interview Q&A / Object-Oriented Programming
Object-Oriented Programming interview questions
The four pillars, interfaces, abstract classes and design basics.
Prefer rapid revision? Practise Object-Oriented Programming short interview answers →
- Does Python have private attributes? What do _x and __x mean?
Python has no true private. A single underscore _x is a hint that it is internal. A double underscore __x triggers name mangling, which renames it to _ClassName__x to avoid clashes in subclasses.
IntermediateQuick answer1 min read - How would you build a simple factory in Python without a long if-elif chain?
Keep a dictionary that maps names to classes and look the class up. Adding a new type is a one-line registration rather than another elif branch.
IntermediateQuick answer1 min read - What is the difference between a shallow copy and a deep copy of an object?
A shallow copy duplicates the object but shares the objects it refers to. A deep copy duplicates the whole graph, so the copy shares nothing with the original.
IntermediateQuick answer1 min read