Sitemap

Member-only story

Can We Make the main() Method Final in Java?

Yes, the main() method can be declared final in Java. Learn what it means, how it works, and why it’s allowed with code examples and clear explanations.

3 min readMar 24, 2025

--

Introduction

If you’ve been brushing up on Java basics or preparing for interviews, you’ve probably seen this popular question:

Can we make the main() method final in Java?

The short answer is:
Yes, you can declare the main() method as final.

But let’s understand why, what it means, and whether it’s useful or just a trick interview question.

📌 The Standard main() Method

In Java, the standard method signature that the JVM looks for to start execution is:

public static void main(String[] args)
  • public: So the JVM can access it from outside your class.
  • static: So it can be called without creating an object.
  • void: No return value.
  • String[] args: Accepts command-line arguments.

✅ So, Can It Be Final?

Yes! You can declare it like this:

public static final void main(String[] args) {
System.out.println("Final main method works!");
}

Java will compile and run it without any issues.

🔎 What Does final Mean for Methods?

In Java, marking a method final means:

You cannot override this method in a subclass.

So if you write:

public final void show() {
// logic
}

Any subclass can’t override show().

🧪 What Happens When You Mark main() as Final?

Nothing changes in terms of execution. The JVM doesn’t care whether main() is final or not — it only needs it to be:

public static void main(String[] args)

--

--

No responses yet