Purpose of override

Gur*_*epS 7 java oop overriding

This is a very naiveish question, but here goes:

An overriden method from a base class will mean that calls to the sub class will call the derived, overriden method, correct?

Thus, if there is no override annotation, the method in the base class will be called. So the override method will serve purely to document the intent - call one version of a method over the other.

Is this the case?

This leads me to the following question:

What is the difference between an abstract class which 5-6 classes may derive from but the methods inherited in the derived classes are not overriden, and one class (Static or not being irrelevant), used by those 5-6 classes?

Jim*_*son 10

@Override注释仅用于在编译时捕获错误.它不会影响运行时的覆盖行为.我们的想法是让编译器有机会通知您方法名称或签名是错误的.

  • 当您考虑代码随时间的变化时,它尤其有用.如果您的子类重写基类的方法,但稍后某人更改了基类中的方法签名,则您的子类不再覆盖任何内容,这可能是不正确的.@Override告诉编译器该方法应该覆盖某些东西,因此它将在构建时跳闸,让您调查并纠正这种情况.将其视为构建时断言. (6认同)