如何用另一个类对象从主类调用主类的方法。
请帮我

StudentRecord.java

package com.test;
public class  StudentRecord {
    public String name;
    public int rollNumber;
    public String departement;
    public float    totalMark;
    boolean hasReservation;

    public  StudentRecord(){
        name           = new String("");
        rollNumber     = 0;
        departement    = new String("");
        totalMark      = 0;
        hasReservation = false;
    }
    public String toString() {
        return "[" + departement+ ","+ name + "," + rollNumber +"]";
    }
}


Test.java

package com.test;
public class Test {
    public native static StudentRecord[] getStudentDetails();
    public static void main(String[] args) {
        System.loadLibrary("Sample");
        int a= 10;
        StudentRecord[] records = getStudentDetails();
        for(StudentRecord record:records){
            System.out.println("Name:"+record.name);
            System.out.println("Roll Number:"+record.rollNumber);
            System.out.println("Departement:"+record.departement);
            System.out.println("Total Marks:"+record.totalMark);
            System.out.println("Has Reservation:"+record.hasReservation);
        }

    }
}


 error: cannot find symbol
         StudentRecord[] records = getStudentDetails();
                     ^
  symbol:   class getStudentDetails
  location: class eventJava
eventJava.java:22: error: cannot find symbol
       for(Record record:records){
                         ^
  symbol:   variable records
  location: class test
2 errors

最佳答案

您可以通过新的Test()。getStudentDetails()而不是getStudentDetails()尝试一下,猜想这对您有用

关于java - 如何用Java中的另一个类对象从主类调用主类的方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60407110/

10-10 02:29