If static
members are not inheriting then why we can access it using sub class reference. Like in the given example we should not be able to access static method from class A by using Class A reference.
package me.addicted.to.java;
public class B extends A
{
public static void main(String[] args)
{
A.method();
B.method();
A a1 = new B();
B test = new B();
A arr[] = {a1,test};
for(int i = 0; i < 2; i ++){
arr[i].method();
}
}
}
class A
{
static int i = 10;
static void method(){
System.out.println("From Hello A");
}
}
Output :
From Hello A
From Hello A
From Hello A
From Hello A