Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Follow publication

Member-only story

Can You Override Private or Static Methods in Java?

2 min readMar 25, 2025

--

🔍 Quick Answer

1️⃣ Why You Can’t Override private Methods

  • private methods are not inherited by subclasses.
  • Therefore, you cannot override them.

📌 Example:

class Parent {
private void showMessage() {
System.out.println("Parent's showMessage");
}
}

class Child extends Parent {
private void showMessage() {
System.out.println("Child's showMessage");
}
}

Even though both classes have a method named showMessage(), it’s not overriding — it’s just a new private method local to each class.

🔒 Private methods are completely hidden from subclasses.

2️⃣ Why You Can’t Override static Methods

  • static methods belong to the class, not the instance.
  • So they cannot be overridden, only hidden.

This is called method hiding, not overriding.

📌 Example:

class Parent {
static void show() {
System.out.println("Parent's static show()");
}
}…

--

--