I was told that static methods in java do not have Inheritance, but when I try the following test
package test1;
public class Main {
public static void main(String[] args) {
TB.ttt();
TB.ttt2();
}
}
package test1;
public class TA {
static public Boolean ttt()
{
System.out.println("TestInheritenceA");
return true;
}
static public String test ="ClassA";
}
package test1;
public class TB extends TA{
static public void ttt2(){
System.out.println(test);
}
}
printed:
TestInheritenceA ClassA
therefore, static java methods (and fields) have inheritance (if you try to call a class method, it goes along the inheritance chain, looking for class methods). Is this really not so? And are there any OO inheritance languages that are confused with class methods?
So, apparently, static methods are inherited, but cannot be overridden, just as C # shares this issue? Are there any other languages?
source
share