Java Zero to All All questionsPractise free
Interview questions › JVM Internals & Runtime › JVM Architecture

What is the parent-delegation model and what concrete problems does it prevent?

Level III · MidJVM Architecture
Short answer

Before a class loader tries to define a class itself, it delegates upward to its parent, so the bootstrap loader gets first refusal.

Explanation

This prevents user code from shadowing core JDK classes (you can't sneak in your own java.lang.String) and avoids loading the same core class twice under different loaders. The gotcha is that two classes with the identical name loaded by different loaders are distinct types, so a cast between them throws ClassCastException even though the bytecode is identical.

Common mistakes
  • Saying child loaders are asked first.
  • Not explaining that delegation stops user code from replacing core classes.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for JVM Architecture.

Practise free

More on JVM Architecture