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

Java · Theory

Compile-Time Polymorphism in Java

← All stacks

Theory

71/270

Compile-Time Polymorphism in Java

Polymorphism — one name, many forms. Compile-time: overloading.

Runtime — parent reference, child object, overridden method.

Interview line — Animal a = new Cat(); a.sound(); → Meow.

Write one tiny example for Compile-Time Polymorphism. Compile, print one result, and say the output out loud before you type.

Use Compile-Time Polymorphism only when the problem needs it. Don’t force it into every program. Know one beginner trap.

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

Exam tip

Write Animal a = new Cat(); then say which sound() runs.

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();
  }
}

Compile-Time Polymorphism in Java — output: Meow. a looks like Animal, but the real object is Cat — runtime polymorphism.

Short notes

  • DefCompile-Time Polymorphism is a Java idea you should explain with one small example.
  • RuleKnow the keyword / API used for Compile-Time Polymorphism. Type a tiny Main and print one result.
  • RememberFor Compile-Time Polymorphism, say the output before you code.
  • TrapCompile-Time Polymorphism — only memorising the heading. No example, no trap.
  • One name, many forms
  • Overload = compile time

Questions

1

What is Compile-Time Polymorphism?

2

Why do we use Compile-Time Polymorphism in Java?

3

Write one small example of Compile-Time Polymorphism.

4

What mistake do beginners make with Compile-Time Polymorphism?

5

Where is Compile-Time Polymorphism used in a real program?

Previous← Abstraction in JavaNextDynamic Method Dispatch 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.