The term redefinition usually refers to objects, because using the same parent link, you can call different methods from this child object. Therefore, static methods cannot be overridden because they are associated with a reference type, not an object type.
? , . , , , . :
public class TestOverriding {
public static void main(String aga[]) {
Fest t = new Fest();
t.tests(); <-- prints "Test class : tests"
}
}
class Test {
static void tests() {
System.out.println("Test class : tests");
}
}
class Fest extends Test {
void tests3() {
System.out.println("Fest class : tests");
}
}
, . . , .
1:
class Fest{
void tests3() {
System.out.println("Fest class : tests3");
}
static void tests3() {
System.out.println("Fest class : static tests3"); <-- gives "method tests3() is already defined in class Fest"
}
}
2: ( )
class Test {
static void tests() {
System.out.println("Test class : tests");
}
}
class Fest extends Test {
void tests() { <-- gives "overridden method is static"
System.out.println("Fest class : tests");
}
}
2: ( )
class Test {
oid tests() {
System.out.println("Test class : tests");
}
}
class Fest extends Test {
static void tests() { <-- gives "overriding method is static"
System.out.println("Fest class : tests");
}
}