+ 3

In which "@Override" used in java ?

7th Jul 2017, 6:03 PM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar
2 Answers
+ 16
It's an annotation that prepares the compiler for overriding... Can be omitted....
7th Jul 2017, 6:06 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 11
In addition to ValentinHacker's answer, It works as a safety measure. If you use this annotation, the compiler will get to know that you're going to write an overriden method next. So it'll be able to show error if you make any mistake while writing the prototype. public double calculateGrade(){ // parent method // implementation } public double calculategrades(){ // overriden method in child class // no error in spite of different spelling } @Override public double calculategrades(){ /* will show error, because there's no matching prototype in parent class */ } It's a good practice to use this annotation to avoid mistake.
7th Jul 2017, 7:07 PM
Shamima Yasmin
Shamima Yasmin - avatar