static methods and variabels(static and non static) can not be overridden, they can only be hidden. But rules for hiding both static methods and static variables are different.
For hiding a static method, all rules of overriding a method are applied.
a.) name should be same
b.) parameter sequence and types should be same
c.) same static modifier should be there
d.) and access modifier can be widen not narrower (means check that init() in A class with default access modifier and in B it could be protected or public but can not be private)
class A
{
static void init(int i)
{
}
}
class B extends A
{
public static void init(int i)
{
}
}
>>>>>>>>>>>>>>Now in case of member variables(local)/class variables (static)...Keep on thing in mind, we can;t override any type of variable, variables can only be hidden.
Rule for variable to be hidden
variabel name should be same (no matters what is type of variable)
class A
{
int local=10;
static int i_am_static=2;
}
class B extends A
{
private
String local="I am hidning local of A";
static String i_am_static="I am hiding static variable of A";
public static void main(String args[])
{
B b = new B();
System.out.println("b.local :"+b.local);
System.out.println("b.i_am_static :"+b.i_am_static);
A a =b;
System.out.println("a.local :"+a.local);
System.out.println("a.i_am_static :"+a.i_am_static);
}
}
/***
output is
b.local :I am hidning local of A
b.i_am_static :I am hiding static variable of A
a.local :10
a.i_am_static :2
*/
I think this will help you upto some extent.