-2
public interface Game{
   public abstract boolean isValid(int coup);
}
public Machin implements Game{

   //Do I need to write @Override here ?
   public boolean isValid(int coup){
     //exemple
     if (coup==0){
        return false
     }
     return true
   }

}

I don't understand Overriding with abstract method could you help me ? Do I need to put @Override ?

1 Answers1

0

Overriding is when a subclass method is different than that of its superclass. Interfaces do not have method bodies - they solely force all classes that implement to have these functions. You do not need the override tag in the Machin class but if you were to create a subclass of with an isValid() method, you would need to override.

A Bear
  • 59
  • 6
  • Okay thank's for help ^^ – Nathan 1132 Dec 13 '20 at 22:42
  • 1
    I wish to point out a couple things here. 1) The `@Override` annotation doesn't really do anything for most compilers, so it's mostly just a hint for the reader. The code will run just fine with or without the annotation. 2) Interfaces **can** have method bodies through the use of default implementations. 3) The `@Override` annotation can prevent you from doing stupid things, like messing with the method header. For these reasons, I would recommend using the `@Override` annotation on the `isValid()` method to indicate that this is indeed overriding a method from the `Game` interface. – Charlie Armstrong Dec 13 '20 at 23:00
  • Oh thank's a lot it's more clear now – Nathan 1132 Dec 14 '20 at 14:21