Class vs object
A class is a blueprint; an object is a concrete thing built from that blueprint.
class Dog: # the blueprint
def __init__(self, name):
self.name = name
def bark(self):
return "Woof!"
rex = Dog("Rex") # an object (instance)
fido = Dog("Fido") # another object
The four pillars
Dog is an Animal and gets its behavior for free..speak() on any Animal and each type responds its own way.Overloading vs overriding
A classic trap. Both involve methods with the same name, but they are very different.
| Overloading | Overriding | |
|---|---|---|
| Where | Same class | Subclass redefines a parent method |
| Signature | Same name, different parameters | Same name and parameters |
| Resolved | At compile time (static) | At run time (dynamic) |
| Purpose | Convenience (many ways to call) | Polymorphism (change behavior) |
# Overloading: same name, different params (same class)
add(2, 3)
add(2, 3, 4)
# Overriding: subclass changes behavior (same signature)
class Animal: def speak(): "..."
class Dog(Animal): def speak(): "Woof" # overrides
Abstract class vs interface
Both define a contract subclasses must follow, but they differ.
| Abstract class | Interface | |
|---|---|---|
| Methods | Can have both implemented and abstract methods | Traditionally only method signatures (a pure contract) |
| State | Can have fields/state | Typically no instance state |
| Inheritance | A class extends one abstract class | A class can implement many interfaces |
| Use when | Sharing common code among related classes | Defining a capability many unrelated classes can have |
startEngine() plus a blank drive() to fill in. An interface is a capability like "Swimmable", a duck, a fish, and a submarine are unrelated, but all can implement swim().SOLID principles (high level)
Five guidelines for clean, maintainable OOP. You do not need to memorize definitions, know what each aims for:
- S - Single Responsibility: a class should have one reason to change.
- O - Open/Closed: open to extension, closed to modification.
- L - Liskov Substitution: a subclass should be usable anywhere its parent is.
- I - Interface Segregation: many small interfaces beat one fat one.
- D - Dependency Inversion: depend on abstractions, not concrete classes.
Final quiz
Ten questions across classes, the four pillars, overloading/overriding, abstract vs interface, and SOLID. Aim for 7+.
What to do next
Read each section, then take its quiz to check yourself. The final quiz scores you out of 10. Examples use simple, language-neutral pseudocode so the ideas transfer to Java, C++, Python, or C#. This is the deep dive for the CS Fundamentals OOP section. Confused? Tap ✦ Ask AI.