求解~为什么我的这段代码在eclipse中不能运行?

package testwork;

class ShiStudent {

//学生类的相关数据和方法的调用
String name="";
String sex="";
int age=0;
float score=0.0f;

//输出说话内容
public void speak(String inStr) {
    System.out.println("自我介绍:我叫"+name+",");
}
//输出得分
public void grade(float inscore) {
    System.out.println("Java考试得分"+inscore);
}

public class Student{
public static void main(String[]args) {
ShiStudent stu1=new ShiStudent();
stu1.name="倪爱学";
stu1.sex="男";
stu1.age=20;
stu1.score=91.5F;
stu1.speak("年龄"+stu1.age+"岁,");
stu1.grade(stu1.score);
ShiStudent stu2=new ShiStudent();
stu2.name="雍心误";
stu2.sex="女";
stu2.age=18;
stu2.score=95;
stu2.speak("年龄"+stu2.age+"岁,");
stu2.grade(stu2.score);

}

}

}

你类嵌套了,这个两个类放在一个文件里,你现在是把Student嵌套到ShiStudent 里面了

试了一下没问题哦~
怀疑你多了个},去掉一个}

img

你的代码结构有问题:

class ShiStudent {
    // 学生类的相关数据和方法的调用
    String name = "";
    String sex = "";
    int age = 0;
    float score = 0.0f;

    // 输出说话内容
    public void speak(String inStr) {
        System.out.println("自我介绍:我叫" + name + ",");
    }

    // 输出得分
    public void grade(float inscore) {
        System.out.println("Java考试得分" + inscore);
    }
}

public class Student {
    public static void main(String[] args) {
        ShiStudent stu1 = new ShiStudent();
        stu1.name = "倪爱学";
        stu1.sex = "男";
        stu1.age = 20;
        stu1.score = 91.5F;
        stu1.speak("年龄" + stu1.age + "岁,");
        stu1.grade(stu1.score);
        ShiStudent stu2 = new ShiStudent();
        stu2.name = "雍心误";
        stu2.sex = "女";
        stu2.age = 18;
        stu2.score = 95;
        stu2.speak("年龄" + stu2.age + "岁,");
        stu2.grade(stu2.score);
    }
}