Who is Method Overriding?

Method overriding is when a child uses its own special version of something that was already used by its parent.

Imagine you and your friend both have a toy robot. Your robot says "Hello!" when it starts up. But your friend’s robot has been upgraded, it now says "Hi there!" instead. Even though both robots do the same job (greeting), your friend's version is different.

This is like method overriding in programming. The parent class (like your robot) has a method that does something, and the child class (like your friend’s robot) changes it to work differently, but keeps the same name.

How It Works in Real Life

Think of it like this:

  • Your mom makes chocolate cake every Sunday.
  • One day, you decide to make vanilla cake instead.

You're still making a cake (same task), but your version is different.

In coding terms:

  • Mom's makeCake() method = chocolate cake
  • Your makeCake() method = vanilla cake

The name of the action is the same, but the way it’s done changes, just like in method overriding!

Take the quiz →

Examples

  1. A dog can bark, but a puppy can whine. Both are dogs, but they have different ways of making noise.
  2. A car drives, but a sports car zooms. Both are cars, but they move differently.
  3. A chef cooks, but a pastry chef bakes. Both are chefs, but their speciality differs.

Ask a question

See also

Discussion

Recent activity