@Override

I’m sorry for posting a lot lately, but I strive to get better. My question is, what does @Override mean as a theory/concept? Does it mean that it happens succesively or with other @Overrides?

Hi memonick,

the @Override-notation simply declares that a method implements/overrides a method from its (abstract) super class or its interface.

If the following interface:

[java]

public interface MyInterface {

void execute();

}[/java]

is implemented by the following class:

[java]

public class MyClass implements MyInterface {

@Override

public void execute() {

// implementation of method execute()

}

}[/java]

you have to implement the method execute(). That concept is meant by @Override. Hope that it answered the question. What do you mean with “… that it happens succesively or with other @Overrides”?

Regards

Moe

Oh, I understand its concept now. Nevermind what I wrote. Thanks a lot!

It means that the method below re-implements the method with the same name/parameters of the parent class.



Note that this annotation is not mandatory (it’s been introduced in java 5), and it’s just there to hint the compiler that this method should be in the parent class, also it give better readability to your code. So if you override a method without this annotation, it will work just as fine (any good IDE will warn you to add it though).

If you put this annotation on a method that is not in the parent class, the compiler will throw an error.



Hope that helps



edit : erf too slow.

Thanks :slight_smile: