Question:
PLEASE ANSWER, OVERRIDING METHOD?
2014-05-22 13:13:48 UTC
Which statement is true?

Customer and KeyHolders are classes. KeyHolder extends Customer.

1) The line @Override will prevent the code from compiling because assignBike in KeyHolder does not override anything.

2) The line @Override is essential because assignBike in KeyHolder override assignBike in Customer; if it is removed the code will not compile.

3) If the line @Override is removed the code will still compile but assignBike KeyHolder will not override the version inherited from Customer.

4) The line @Override makes the compiled code more compact because it allows compiler to ignore the overridden version of assignBike in Customer.

5) The line @Override is an optional annotation; removing it has no effect on the compiled code.
Three answers:
2014-05-22 13:19:46 UTC
I assume you have some code to go with this question?



FYI, @override informs the compiler that you are attempting to override a function in the parent. If there isn't a function with the exact same name and same parameters in the parent then the compiler will warn you (or error, depending on your compiler settings).
2014-05-22 13:17:09 UTC
I believe that all the @ tags are generated by ide's and such, but do not affect anything. It allows for API generation if you have that capability. If you use eclipse you see that in gray font. I do not believe it affects compile time, but the easiest way to check was to make a simple class, and then have a subclass extend it, and check if it compiles under those circumstances.
?
2014-05-23 05:21:25 UTC
Further to Asian boy's answer:



@ tags (or annotations) are sometimes generated by IDEs, but a programmer may choose to enter them manually



Annotations are not quite the same as comments. If the compiler sees an @override tag then it will check that the method actually is being overridden and will produce a warning if the tag is incorrect. Certain other tags also affect the way the compiler behaves. In addition, the reflection api can pick up annotations at run time, and hence the presence or absence of an annotation may affect the behaviour of a program when it's running


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...