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

Java · Theory

Polymorphism in Java

← All stacks

Theory

41/270

Polymorphism in Java

Polymorphism means one name, many forms. Compile-time: method overloading — same name, different parameters. Runtime: method overriding — parent reference, child object.

Classic line: Animal a = new Dog(); a.sound(); calls Dog’s version at runtime. That lets you write flexible code. Add a new child class without rewriting all callers.

Don’t mix the two definitions. Overloading is decided at compile time. Overriding is decided at runtime. Give one example each.

Let's take this on the board with one tiny Main class — no extra files. Polymorphism in Java — output: Meow. Reference type is Animal, real object is Cat — runtime polymorphism. Start from main, go line by line, and stop at each print. That output is the proof for Polymorphism.

Exam tip

Overloading vs overriding — two examples, two timings.

Example

class Animal {
  void sound() { System.out.println("Some sound"); }
}
class Cat extends Animal {
  @Override
  void sound() { System.out.println("Meow"); }
}
public class Main {
  public static void main(String[] args) {
    Animal a = new Cat();
    a.sound();
  }
}

Polymorphism in Java — output: Meow. Reference type is Animal, real object is Cat — runtime polymorphism.

Short notes

  • DefPolymorphism = one name, many forms.
  • RuleOverloading = compile-time. Overriding = runtime.
  • RememberAnimal a = new Dog(); a.sound(); → Dog’s version.
  • UseAdd new child classes without rewriting callers.

Questions

1

What is polymorphism?

2

What is compile-time polymorphism?

3

What is runtime polymorphism?

4

What does Animal a = new Dog(); a.sound(); call?

Previous← Final Keyword in JavaNextStatic and Dynamic Binding 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.