hai
i want to clarify one doubt regarding static method.
in K&B Scjp1.6 page no 161 at chapter 2 they specified static method can't be overriden but i executed this below code i got different thing
class A {
// public static void display(){
static void display(){
System.out.println ("Static method of A ");
}
}
class B extends A {
static void display(){
System.out.println ("Static method of B ");
}
}
class Static {
public static void main(
String Args[]) {
A a=new A();
B b=new B();
a.display();
b.display();
}
}
output
Static method of A
Static method of B
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if i write method in A with public specifier like public static void display(){
i am getting compile time error like
Static.java:10: display() in B cannot override display() in A; attempting to assign weaker access privileges; was public
static void display(){
normally the above error comes in overiding instance method trying to assign weaker pevilleges in Sub class if static method can not be able overridden means why the above message is comming