class LeapYear
{
public static void main(String[] args)
{
IsLeapYear(1999);
IsLeapYear(2008);
}
static void IsLeapYear(int year)//这个地方为什么去掉public就会报错呢
{ boolean flag;
flag=false;
if(year%4==0){flag=true;}
if(year%400==0){flag=true;}
if(year%100==0){flag=false;}
if(flag)
{
System.out.println(""+year+"is LeapYear.");
}
else
{
System.out.println(""+year+"is not LeapYear.");
}
}
}
报错为:LeapYear.java:5: non-static method IsLeapYear(int) cannot be referenced from a s
tatic context
IsLeapYear(1999);
^
LeapYear.java:6: non-static method IsLeapYear(int) cannot be referenced from a s
tatic context
IsLeapYear(2008);
^
2 errors
{
public static void main(String[] args)
{
IsLeapYear(1999);
IsLeapYear(2008);
}
static void IsLeapYear(int year)//这个地方为什么去掉public就会报错呢
{ boolean flag;
flag=false;
if(year%4==0){flag=true;}
if(year%400==0){flag=true;}
if(year%100==0){flag=false;}
if(flag)
{
System.out.println(""+year+"is LeapYear.");
}
else
{
System.out.println(""+year+"is not LeapYear.");
}
}
}
报错为:LeapYear.java:5: non-static method IsLeapYear(int) cannot be referenced from a s
tatic context
IsLeapYear(1999);
^
LeapYear.java:6: non-static method IsLeapYear(int) cannot be referenced from a s
tatic context
IsLeapYear(2008);
^
2 errors