PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Method Overriding in Java

← All stacks

Theory

36/270

Method Overriding in Java

Overriding = child rewrites a parent method with the same signature: same name, same parameters. Put @Override so the compiler catches mistakes.

At runtime, a parent reference can call the child’s version: Animal a = new Dog(); a.sound();. Access cannot be tighter in the child. Purpose is specialised behaviour.

If you change parameters, it is not overriding — it becomes overloading or a new method. Show Animal/Dog sound() with a parent reference.

Let's take this on the board with one tiny Main class — no extra files. Method Overriding in Java — output: 25. square(5) returns 5*5. Change to square(6) → 36. Start from main, go line by line, and stop at each print. That output is the proof for Method Overriding.

Exam tip

Parent ref + child object demo for overriding.

Example

public class Main {
  static int square(int n) { return n * n; }
  public static void main(String[] args) {
    System.out.println(square(5));
  }
}

Method Overriding in Java — output: 25. square(5) returns 5*5. Change to square(6) → 36.

Short notes

  • DefOverriding = child rewrites parent method with the same signature.
  • RuleSame name + same parameters. Use @Override.
  • RememberParent ref + child object → child’s version at runtime.
  • TrapChanging params is not overriding.

Questions

1

What is overriding?

2

Why @Override?

3

When is overriding decided?

Previous← Method Overloading in JavaNextCovariant Return Type in Java →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.