参数中的System.out

who*_*med 0 java

我有一个测试文件,根据它,我需要构建我的程序,测试文件在下面.但是,我对s1.showDetails(System.out)感到困惑; 我从来没有遇到参数System.out任何人都可以帮助.怎么办呢??? 当我尝试编写showDetails()时,编译器会写错误.我的学生代码在此之下谢谢你提前!

import java.util.*;
public class Q2 {
    public static void main(String [] args)
    {
        // Start on section A
        System.out.println("Question 2");
        System.out.println("Start on part A");
        Student s1 = new Student("John", "Smith", 42);
        s1.showDetails(System.out);
        Course cs = new Course("Computer science");
    }
}

public class Student {
    private String name;
    private String familyName;
    private int moduleMark;
    private int total;
    protected Student(String name, String familyName, int moduleMark)
    {
        this.name = name;
        this.familyName = familyName;
        this.moduleMark = moduleMark;
    }

    public String getName()
    {
        return name;
    }

    public String getFamilyName()
    {
        return familyName;
    }

    public int getModuleMark()
    {
        return moduleMark;
    }

    public String showDetails()
    {
        return (this.name + " " + this.familyName + " " + moduleMark + total);
        //print(name);
    }
}
Run Code Online (Sandbox Code Playgroud)

mic*_*cha 6

System.out 是一个像其他变量一样的变量.

系统是一个类

out是类型public staticSystem的变量PrintStream.所以你可以访问它System.out

所以System.out.println(..)只是调用一个println(..)函数PrintStream

所以你的功能应该是这样的:

public String showDetails(PrintStream stream) {
 ...
}
Run Code Online (Sandbox Code Playgroud)