This question already has an answer here:
- Are static variables inherited 3 answers
We know that in java static variable are not inherited. But in below code I am not getting any error as I want to initialize the static variable in child class.
class s
{
static int x;
}
class aaa extends s
{
void fun()
{
x=2;
System.out.println(x);
}
public static void main(String args[])
{
aaa w=new aaa();
w.fun();
}
}
static
members are most definitely accessible from subclasses, as your example shows. You cannot override them, of course, but you could hide them.