Programming core
Object-Oriented Programming
5 self-contained study topics — notes, diagrams, formulas, and worked examples for exams and GATE.
Topics
- Classes and ObjectsA class is a blueprint defining state and behaviour; an object is a concrete instance with its own field values, created by a constructor, with the this/self reference letting methods act on the specific instance that received the call.
- Inheritance and PolymorphismInheritance lets a subclass reuse and extend a superclass (an IS-A relationship), and polymorphism lets a base-type reference invoke the correct overridden method of the actual object at runtime through dynamic dispatch.
- Abstraction and EncapsulationAbstraction exposes what an object does while hiding how, through abstract classes and interfaces; encapsulation enforces that hiding by keeping fields private and mediating access through methods, so internals can change without breaking clients.
- Exception HandlingException handling separates error handling from normal logic: a try block runs risky code, catch blocks handle specific error types, and finally always runs for cleanup; an uncaught exception unwinds the call stack until a handler is found.
- Design PrinciplesDesign principles like SOLID and DRY guide maintainable object-oriented code by promoting single responsibility, extensibility without modification, substitutable subclasses, focused interfaces, and dependence on abstractions.