The Java object array is a little different from the normal array. Actually, the bottom-up principle is the same. We use object arrays to remember to create objects or to report null pointer exceptions,
I've met twice and wasted a lot of time. Now, let's take a look at the initialization process. You must remember that the new object is not only in front of the new array
public class Student
{
Private String username;
private int num;
Public Student (String username, int num)
{
This.username = Username;
This.num = num;
}
public static void Main (string[] args)
{
Student s[] = new STUDENT[10];
for (int i = 0; i < s.length; i++)
{
S[i] = new Student (i + "", I);
System.out.println (S[i]);
}
}
Public String GetUserName ()
{
return username;
}
public void Setusername (String username)
{
This.username = Username;
}
public int Getnum ()
{
return num;
}
public void setnum (int num)
{
This.num = num;
}
@Override
Public String toString ()
{
return this.num + "" + this.username;
}
}
Java Object array