OOP Notes for Placements and Interviews

Object-oriented programming notes for placement interviews: classes, encapsulation, inheritance, polymorphism, abstraction, SOLID and design patterns, with code.

  • Notes: 11
  • Reading time: about 3 hours
  • Cost: Free, no sign-in needed

Classes and objects, encapsulation, inheritance, polymorphism, abstraction, SOLID and the design patterns interviews ask for.

Read in this order

  1. Introduction to Object-Oriented Programming — What object-oriented programming is: classes and objects, the four pillars of OOP, procedural vs OOP, and how C++, Java and Python each do it.
  2. Classes and Objects — Classes and objects in OOP: fields and methods, default, parameterised and copy constructors, destructors vs garbage collection, this, static members.
  3. Encapsulation — Encapsulation in OOP: data hiding, access modifiers compared across C++, Java and Python, getters and setters with validation, and immutable classes.
  4. Inheritance — Inheritance in OOP: the is-a relationship, single, multilevel, hierarchical, multiple and hybrid types, overriding, super, constructor order, diamonds.
  5. Polymorphism — Polymorphism in OOP: compile-time overloading vs run-time overriding, dynamic dispatch and the vtable, upcasting, downcasting and object slicing.
  6. Abstraction: Abstract Classes and Interfaces — Abstraction in OOP: abstract classes, C++ pure virtual functions, Java interfaces with default and static methods, Python ABCs, and when to use which.
  7. Association, Aggregation and Composition — Association, aggregation and composition in OOP: has-a vs is-a, object lifetimes, UML notation, ownership in C++, and composition over inheritance.
  8. SOLID Principles — The five SOLID principles of OOP design — single responsibility, open/closed, Liskov, interface segregation, dependency inversion — with violations and fixes.
  9. Design Patterns for Interviews — OOP design patterns for interviews: creational, structural and behavioural, with Singleton, Factory, Builder, Adapter, Decorator, Observer and Strategy.
  10. Object Equality, Hashing and Copying — Object identity vs equality in OOP: == vs equals in Java, == vs is in Python, operator== in C++, the equals/hashCode contract, and shallow vs deep copy.
  11. Exception Handling in OOP — Exception handling in OOP: try, catch and finally, checked vs unchecked exceptions in Java, custom exception classes, RAII and try-with-resources, with code.

Test yourself

Other subjects