โ† Java
#10 most askedVery commonEasyCore Java & OOP

Overloading vs overriding

New to Core Java & OOP? Learn it from scratch first
Inheritance vs Composition โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

What's the difference between method overloading and overriding? Which one is decided at compile time?

๐Ÿ”ฎ Predict the output

class Animal { String sound() { return "..."; } }
class Dog extends Animal { @Override String sound() { return "woof"; } }
public class Main {
    static String describe(Animal a) { return "animal says " + a.sound(); }
    static String describe(Dog d) { return "dog says " + d.sound(); }
    public static void main(String[] args) {
        Animal pet = new Dog();
        System.out.println(describe(pet));
    }
}

๐ŸŽค Answer it out loud, then check yourself

Say your answer as if the interviewer is listening (30โ€“90 seconds). Then reveal what a strong answer covers and tick what you said.

    Answer out loud first, then compare.
    Want to rehearse it?
    Answer this to the AI interviewer and get a verdict โ†’