Following is what I have done so far, but I get an exception every time I run it:
class Student{
int sNo;
}
public class Array {
public static Student[] createObj() {
Student[] s = new Student[10];
for(int i = 0; i<10;i++) {
s[i].sNo = i+1;
}
return s;
}
public static void main(String[] args) {
Student student[] = createObj();
for(int i = 0; i<10;i++) {
System.out.print(student[i].sNo);
}
}
}
This is the exception:
Exception in thread "main" java.lang.NullPointerException
at Array.createObj(Array.java:9)
at Array.main(Array.java:14)