YOU MIGHT ALSO LIKE
ASSOCIATED TAGS
animal  compiler  creating  happens  makesound  method  override  overriding  polymorphism  println  public  signature  subclass  superclass  written  
LATEST POSTS

Can an Overriding Method Only Be Written in a Subclass?

Understanding Method Overriding at Its Core

Before we get into the nitty-gritty, let’s get something straight: method overriding happens only when a subclass redefines a method that already exists in its superclass. Full stop. You cannot override a method within the same class—that’s not overriding, it’s just re-declaring, or more accurately, creating a method conflict (which will likely blow up your compiler's mind).

What's Overriding, Anyway?

In object-oriented programming (OOP)—Java, C#, Python (to some extent), etc.—overriding lets a subclass give its own twist on a method it inherits.
Think of it like this:

  • Superclass: public void makeSound() { System.out.println("Generic sound"); }

  • Subclass (Dog): public void makeSound() { System.out.println("Bark bark"); }

Boom. That’s overriding.

Why Overriding Requires a Subclass

Compiler Rules Are Brutal

If you try to write two methods with the same name and signature in one class, you’ll get an error (unless they're overloads, but that’s another story). Overriding demands an inheritance relationship.
No subclass, no override.

Override vs Overload: Don’t Mix ‘Em Up

  • Override: same method signature, different class (subclass), same return type

  • Overload: same method name, different parameters, same class or subclass—it’s just method flexibility

I remember once in a Java assignment, I duplicated a method by accident and thought I was “overriding” something. Nah. The compiler spat fire, and I learned the difference real fast.

What Happens If You Try It in the Same Class?

The Compiler Says NO

Let’s say you try this:

java
public class Cat { public void speak() { System.out.println("Meow"); } public void speak() { System.out.println("Purr"); }}

You think you're being clever? Nope. That’s an error: duplicate method speak().
Only one method with the same name and signature can exist in a class.

What If the Signatures Differ?

That’s method overloading. Not overriding. Like:

java
public void speak(String sound) { System.out.println(sound); }

Still legal, still not overriding.

Subclass Override in Action

Here’s the proper way:

java
class Animal { public void makeSound() { System.out.println("Some sound"); }}class Dog extends Animal { @Override public void makeSound() { System.out.println("Woof!"); }}

Notice the @Override annotation? It’s not required, but super helpful. It ensures you’re actually overriding, not just creating a sneaky new method by mistake.

Why It Matters in Real Projects

Polymorphism Is King

Overriding makes polymorphism work. You can do this:

java
Animal myDog = new Dog();myDog.makeSound(); // Outputs: Woof!

Imagine a system where you have 20+ animal types. Would you write a separate method for each? Overriding lets you handle them all generically. That’s clean code, baby.

Real-life Anecdote

On a team project once, someone accidentally “overloaded” instead of “overriding.” We spent hours debugging why a method wasn't being called polymorphically. Turns out he had a typo in the method signature. We learned our lesson: @Override is your best friend.

Conclusion: Overriding = Subclass Only, Period.

To answer the question once and for all:
Yes, an overriding method can only be written in a subclass.
Not in the same class. Never. That’s just how inheritance and polymorphism work in OOP.

If you need similar methods in one class, look at overloading. But for redefinition? You gotta subclass. That's just how the game is played.

How much height should a boy have to look attractive?

Well, fellas, worry no more, because a new study has revealed 5ft 8in is the ideal height for a man. Dating app Badoo has revealed the most right-swiped heights based on their users aged 18 to 30.

Is 172 cm good for a man?

Yes it is. Average height of male in India is 166.3 cm (i.e. 5 ft 5.5 inches) while for female it is 152.6 cm (i.e. 5 ft) approximately. So, as far as your question is concerned, aforesaid height is above average in both cases.

Is 165 cm normal for a 15 year old?

The predicted height for a female, based on your parents heights, is 155 to 165cm. Most 15 year old girls are nearly done growing. I was too. It's a very normal height for a girl.

Is 160 cm too tall for a 12 year old?

How Tall Should a 12 Year Old Be? We can only speak to national average heights here in North America, whereby, a 12 year old girl would be between 137 cm to 162 cm tall (4-1/2 to 5-1/3 feet). A 12 year old boy should be between 137 cm to 160 cm tall (4-1/2 to 5-1/4 feet).

How tall is a average 15 year old?

Average Height to Weight for Teenage Boys - 13 to 20 Years

Male Teens: 13 - 20 Years)
14 Years112.0 lb. (50.8 kg)64.5" (163.8 cm)
15 Years123.5 lb. (56.02 kg)67.0" (170.1 cm)
16 Years134.0 lb. (60.78 kg)68.3" (173.4 cm)
17 Years142.0 lb. (64.41 kg)69.0" (175.2 cm)

How to get taller at 18?

Staying physically active is even more essential from childhood to grow and improve overall health. But taking it up even in adulthood can help you add a few inches to your height. Strength-building exercises, yoga, jumping rope, and biking all can help to increase your flexibility and grow a few inches taller.

Is 5.7 a good height for a 15 year old boy?

Generally speaking, the average height for 15 year olds girls is 62.9 inches (or 159.7 cm). On the other hand, teen boys at the age of 15 have a much higher average height, which is 67.0 inches (or 170.1 cm).

Can you grow between 16 and 18?

Most girls stop growing taller by age 14 or 15. However, after their early teenage growth spurt, boys continue gaining height at a gradual pace until around 18. Note that some kids will stop growing earlier and others may keep growing a year or two more.

Can you grow 1 cm after 17?

Even with a healthy diet, most people's height won't increase after age 18 to 20. The graph below shows the rate of growth from birth to age 20. As you can see, the growth lines fall to zero between ages 18 and 20 ( 7 , 8 ). The reason why your height stops increasing is your bones, specifically your growth plates.