我从教科书中得到了这个代码。
class FirstClass
{
int idNo =25;
public static void print()
{
System.out.println("firstclass citizen " + idNo);
}
}
class SecondClass
{
int idNo =24;
public static void print()
{
System.out.println("secondclass citizen" + idNo);
}
}
public class People
{
//FirstClass female;
//SecondClass male;
public static void main(String[] args)
{
System.out.println("people from java world");
FirstClass.print();
SecondClass.print();
}
}
但是在编译这段代码时,我得到了以下错误
People.java:7: error: non-static variable idNo cannot be referenced from a stati
c context
System.out.println("firstclass citizen " + idNo);
^
People.java:16: error: non-static variable idNo cannot be referenced from a stat
ic context
System.out.println("secondclass citizen" + idNo);
^
2 errors