Compile-Time
-
Happens before the program runs (during code compilation).
-
Errors like syntax errors, type mismatches, or method overloading are checked here.
-
Polymorphism Example → Method 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 Example → Method 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
-
selfrefers to the current instance of the class. -
It is not a keyword like
thisin 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?
-
selfis 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()
selfhere → refers toobj, andobjis created at runtime