Above code will result in nullpointerexception when an object to StudentGrades is created as you are trying to access the length of grades before initialization.