In the Java inheritance mechanism, subclasses can overwrite methods in the parent class.
Base.java
public class Base {public
base () {
System.out.println ("base");
}
public void Foo () {
System.out.println (' foo in Father ');
}
Checket.java:
public class Checket extends Base {public
checket () {
super ();
System.out.println ("Checket");
}
@Override public
void foo () {
System.out.println (' foo in Son ');
}
Mainc.java:
public class Mainc {public
static void Main (String [] args) {
checket c = new Checket ();
C.foo ();
}
The Foo function in Checket.java the Foo method in the parent base, and the @override keyword (which I have understood as a keyword) is to tell the compiler that if Foo has this method in the parent class, the compilation passes if it does not exist in the parent class. Then there will be an error:
Thread [main] (Suspended (the method foo () of type Checket must override or implement a Supertype method))
Checket.foo () Line:9
Mainc.main (string[]) line:5
The existence here, refers to the method name, parameters, should be consistent.