I am learning about the concept interface
in Java, specifically about its inheritance with class
. From what I understood, this is a basic code syntax for an interface inheritance
interface one{
void funcOne();
}
class Test implements one{
@Override public void funcOne(){
System.out.println("this is one");
}
}
But when I removed the phrase @Override
, the code still worked fine. So what is the purpose of using that keyword?
- My confusion adds up when testing with
static
methods. For instance the code below would throw an error
interface one{
static void funcOne(){
System.out.println("hello");
}
}
class Test implements one{
@Override static void funcOne() {
System.out.println("This is one");
}
}
But it would not throw an error when @Override
is removed.
When should I use the keyword @Override
, and what does it have to do with static
functions?