To store student information using an array of objects in Java, you can define a Student
class with fields for the student's name, age, and other relevant information. Then, you can create an array of Student
objects and use it to store the student information.
Here's an example of how you can define a Student
class and create an array of Student
objects:
class Student { String name; int age; String major; public Student(String name, int age, String major) { this.name = name; this.age = age; this.major = major; } } Student[] students = { new Student("Alice", 21, "Computer Science"), new Student("Bob", 22, "Physics"), new Student("Charlie", 20, "Biology") };
In this example, we're creating an array of Student
objects with three elements, each representing a different student. You can access the student information using the fields of the Student
objects, for example:
System.out.println(students[0].name); // prints "Alice"
You can find more information about arrays and objects in Java in the Java documentation.