Java / JVM Architecture (Java21) Interview questions
How does class loading follow the delegation model?
When a class loader is asked to load a class, it does not immediately try to load it itself - it first delegates the request up to its parent class loader.
Following the hierarchy described earlier, an Application ClassLoader request first goes to the Platform ClassLoader, which in turn defers to the Bootstrap ClassLoader; only if a parent cannot find the class does control return down the chain, with each loader trying to load it itself before delegating the failure further down.
This means core JDK classes are essentially always found and loaded by the Bootstrap ClassLoader, since a request for java.lang.String, for instance, travels all the way up before any lower loader gets a chance to load its own version.
More Related questions...