I have been playing around with modifiers with static method and came across a weird behaviour.
As we know, static methods cannot be overridden, as they are associated with class rather than instance.
So if I have the below snippet, it compiles fine
//Snippet 1 - Compiles fine
public class A {
static void ts() {
}
}
class B extends A {
static void ts() {
}
}
But if I include final modifier to static method in class A, then compilation fails
ts() in B cannot override ts() in A; overridden method is static final.
Why is this happening when static method cannot be overridden at all?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…