class BaseClass{
static int count1=10;
public void display(){
System.out.println("Invoking display method of Base Class");
}
}
public class SingleInheritance01 extends BaseClass {
int value=200;
static int count2=10;
public static void main(String args[]){
SingleInheritance01 objDerivedClass=new SingleInheritance01();
objDerivedClass.display();
}
}
/*
The object created in Derived Class cannot reference static variables in Base Class as well as
派生我可以使用ClassName访问它-我假设静态变量对于类的实例是通用的。* /
static
变量是类级别的变量,而不是实例级别的变量,因此您无法使用对象进行访问。您可以使用类名BaseClass.count1
来访问它。