class test
{
public test(int d, int m, int y)
{
Year Y = new Year(y);
M=m;
D=d;
}
public void getDayOfYear()
{
System.out.print(Y.isLeapYear());
}
private Year Y;
private int M;
private int D;
}class Year
{
public Year(int y)
{
year = y;
}
public boolean isLeapYear()
{
if( year % 4 == 0 )
{
if( year % 100 == 0 )
{
if( year % 400 == 0 )
return true;
return false;
}
return true;
}
return false;
}
private int year;
}求助。。当我在main里面使用test atest = new test(1,2,2000);
atest.getDayOfYear();编译出现System.out.print(Y.isLeapYear()); 中的Y变量NullPointerException请问如何解决?谢谢!
{
public test(int d, int m, int y)
{
Year Y = new Year(y);
M=m;
D=d;
}
public void getDayOfYear()
{
System.out.print(Y.isLeapYear());
}
private Year Y;
private int M;
private int D;
}class Year
{
public Year(int y)
{
year = y;
}
public boolean isLeapYear()
{
if( year % 4 == 0 )
{
if( year % 100 == 0 )
{
if( year % 400 == 0 )
return true;
return false;
}
return true;
}
return false;
}
private int year;
}求助。。当我在main里面使用test atest = new test(1,2,2000);
atest.getDayOfYear();编译出现System.out.print(Y.isLeapYear()); 中的Y变量NullPointerException请问如何解决?谢谢!
解决方法:
public test(int d, int m, int y)
{
//Year Y = new Year(y);
Y=new Yerr(y);
M=m;
D=d;
}