Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of override

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?

like image 559
GurdeepS Avatar asked Jan 10 '11 21:01

GurdeepS


2 Answers

The @Override annotation is intended ONLY to catch errors at compilation time. It does not affect override behavior at runtime. The idea is that you give the compiler the chance to inform you that your method name or signature is wrong.

like image 159
Jim Garrison Avatar answered Oct 07 '22 00:10

Jim Garrison


The override annotation is simply a marker to show the the method overrides a superclass method.

It being there has no effect at runtime. See here:

http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Override.html

like image 45
Pablojim Avatar answered Oct 07 '22 01:10

Pablojim