Java 如何在另一个方法上显示我的obejct数组

Java 如何在另一个方法上显示我的obejct数组,java,Java,如何在另一个方法上显示我的对象数组?我不知道密码。它给我一个垃圾值,或者像一个地址。我使用了不同的方法,但仍然是垃圾值之类的@dasfas public class Student { public static void main(String[] args) { menu(); } public static void menu(){ Scanner input = new Scanner(System.in);

如何在另一个方法上显示我的对象数组?我不知道密码。它给我一个垃圾值,或者像一个地址。我使用了不同的方法,但仍然是垃圾值之类的
@dasfas

public class Student {


    public static void main(String[] args) 
    {
        menu();
    }

    public static void menu(){
        Scanner input = new Scanner(System.in);

        int choice;
        do{
        System.out.println("CMPE 325 Student Record Holder System");
        System.out.println("--------------------------------");
        System.out.println("1.Add Student");
        System.out.println("2.View Records");
        System.out.println("3.Update Students");
        System.out.println("4.Get Average");
        System.out.println("5.Exit");
        System.out.println();
        System.out.println("--------------------------------");
        System.out.print("Enter your choice: ");
        choice=input.nextInt();
你必须在学生课堂上实施

public class Student {

    @Override
    public String toString() {
        return firstName + " " + lastName; // And so on.
    }
}

您必须在要显示的类中声明方法
toString

public String toString() {
     // Return some string that will represent the object>
     return this.getFirstName(); // For example
}
编辑:

例如,如果要打印
Student2
学生类中的对象:

  • 您必须在
    Student2
    类中声明一个类似上述方法的
    toString()
    方法
  • 然后在
    Student
    类中,您可以像


你能给我一个示例代码吗?我真的不明白。我尝试过dat,但显示仍然是@fdfsasf或@435fdf..@christian
Student2 st = new Student2();

... set attributes...

System.out.print(st);