I
I
Igor2018-12-13 18:30:26
Java
Igor, 2018-12-13 18:30:26

Why isn't static method override in Java?

There are two classes, the second is inherited from the first:

public class Test {
  static public void doStuff() {
    System.out.println("Test static method do stuff!");
  }
}

public class TestChild extends Test {
  static public void doStuff() {
    System.out.println("TestChild static method do stuff!");
  }
}

Everything works, the method is overridden. However, if you add the @Override annotation to the inheritor method , then there will be an error, the text of which reads:
Method does not override method from its superclass

How so? After all, the method is just overridden!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-12-13
@hddn

That's life

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question