class-1
package STUDENT;
public class STUDENTS {
private String name;
public String getname() {
return this.name;
}
public void setname(String name) throws Exception {
if(name==null||name.equals("")) {
throw new Exception("NAME CANT BE EMPTY OR NULL");
}
}
public final int RollNo;
private static int NoFStudents=0;
public static int getNoFStudents() {
return STUDENTS.NoFStudents;
}
public static final int MaxStudents=1000;
public STUDENTS(String name) throws Exception {
if(STUDENTS.NoFStudents==STUDENTS.MaxStudents) {
throw new Exception("LIMIT REACHED");
}
this.setname(name);
STUDENTS.NoFStudents++;
this.RollNo=STUDENTS.NoFStudents;
}
}
class 2-
package STUDENT;
public class STUDENT_CLIENT {
public static void main(String[] args) throws Exception {
int i;
STUDENTS[] Student=new STUDENTS[1000];
for(i=0;i<Student.length;i++) {
Student[i]=new STUDENTS(i+"th");
System.out.println(STUDENTS.getNoFStudents());
}
System.out.println(Student[250].RollNo);
System.out.println(Student[250].getname());
Student[250].setname("kunal");
System.out.println(Student[250].getname());
}
}