compile-time and runtime

Compile-Time

  • Happens before the program runs (during code compilation).

  • Errors like syntax errors, type mismatches, or method overloading are checked here.

  • Polymorphism ExampleMethod Overloading
    ↳ Same method name, different parameters
    ↳ Resolved at compile time

Example:

class Test {
    void show(int a) {}
    void show(String b) {}
}

Runtime

  • Happens while the program is running.

  • Errors like null pointer, array out of bounds, etc., occur here.

  • Polymorphism ExampleMethod Overriding
    ↳ Subclass method replaces parent method
    ↳ Resolved at runtime using object type

Example:

class A {
    void show() { System.out.println("A"); }
}
class B extends A {
    void show() { System.out.println("B"); }
}
A obj = new B();
obj.show(); // Output: B

what about self. is this run or compile?

Arre nice question 👌

🧩 self in Python → runtime concept

  • self refers to the current instance of the class.

  • It is not a keyword like this in Java/C++ → just a naming convention.

  • Gets passed automatically when calling instance methods.

  • Exists only when the object is created at runtime, not during compilation.


💡 So?

  • self is resolved at runtime

  • Python is dynamically typed → no compile-time type checks like Java or C++


Quick example:

class Test:
    def show(self):
        print("Address of object:", self)

obj = Test()
obj.show()
  • self here → refers to obj, and obj is created at runtime
Updated on