class后接student会有八叉我不理解为什么

class后接student会有八叉我不理解为什么

问题描述:

实验要求是编写一个Java程序,在程序中定义一个student类并完善student类的结构
可照着程序模板写的,咋会有八叉我不理解阿不理解

img

img

Student类单独写

public class Student {
    String name;
    int age;
    int chinese;
    int math;
    int english;
    public Student(String name, int age, int chinese, int math, int english) {
        this.name = name;
        this.age = age;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }   
    int total(){
        return this.chinese + this.math + this.english;
    }
    int average(){
        return (int)(total() / 3);
    }
}


尽量一个文件一个class,你能少一大堆错误
ps:这比那些上来就要代码的人强多了,再大的错误,自己也上手搞过,你愿意问,别人也会给你解惑的

你写在了main内部。类的定义一般有三个位置。单独一个文件、同一个文件java类里面(类的{}里面)方法之外、同一个文件类之外(类的{}之外)