Change this to your question / problem / query
public class student {
private String name;
private int marks;
public void setDetails(String n, int m) {
name = n;
marks = m;
}
public void printDetails() {
System.out.println("Name: " + name);
System.out.println("Marks: " + marks);
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Objectarray {
public static void main(String[] args) {
// declaring array of objects
student[] st = new student[2];
Scanner s = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
System.out.println("Student " + (i + 1));
System.out.println("Enter name");
String a = s.next();
System.out.println("Enter marks");
int b = s.nextInt();
st[i] = new student();
st[i].setDetails(a,b);
}
s.close();
ArrayList<student> names = new ArrayList<student>();
for (int i = 0; i < 5; i++) {
names.add(st[i]);
System.out.println(names);
}
// printing details of the objects
/*
* for (int i = 0; i < 5; i++) { st[i].printDetails(); }
*/
}
}