Compile-Time Polymorphism in Java
Polymorphism — one name, many forms. Compile-time: overloading.
Runtime — parent reference, child object, overridden method.
Interview line — Animal a = new Cat(); a.sound(); → Meow.
Write one tiny example for Compile-Time Polymorphism. Compile, print one result, and say the output out loud before you type.
Use Compile-Time Polymorphism only when the problem needs it. Don’t force it into every program. Know one beginner trap.
Let's take this on the board with one tiny Main class — no extra files. Compile-Time Polymorphism in Java — output: Meow. a looks like Animal, but the real object is Cat — runtime polymorphism. Start from main, go line by line, and stop at each print. That output is the proof for Compile-Time Polymorphism.
Write Animal a = new Cat(); then say which sound() runs.