java程序问题 这个程序第8段 和 26 段有错误 错在那里 谢谢 说详细点 帮帮忙 各位大虾

2024-12-20 16:39:14
推荐回答(2个)
回答1:

/*
以StudentTest.java保存,因为StudentTest有public static void main()方法。

主要是一些拼写的错误,程序没问题。
*/

/**
*这个程序主要用来测试类名与文件名的一致性的问题
*/
class StudentTest
{
public static void main(String[] args)
{
//Student aStudent = mew Student();
Student aStudent = new Student();
aStudent.setName("张楠");
aStudent.setStudentNum("20030408");
//System.out.println("学生的姓名是:" +aStudent.getName() ",学号是:" + aStudent.detStudentNum() );
System.out.println("学生的姓名是:" +aStudent.getName() +",学号是:" + aStudent.getStudentNum() );
}
}

class People
{

private String name;
public String getName()
{
return name;
}

public void setName(String strName)
{
name = strName;
}

}
class Student extends People
{
private String studentNum;
public String getStudentNum()
{
return studentNum;
}
//public void setStudevtNum(string strStudentNum)
public void setStudentNum(String strStudentNum)
{
studentNum = strStudentNum;
}
}

回答2:

class Test
{
public static void main(String[] args)
{
Student aStudent = new Student();
aStudent.setName("张楠");
aStudent.setStudevtNum("20030408");
System.out.println("学生的姓名是:" +aStudent.getName()+ ",学号是:" + aStudent.getStudentNum() );
}
}
class People
{

private String name;
public String getName()
{
return name;
}

public void setName(String strName)
{
name = strName;
}

}
class Student extends People
{
private String studentNum;
public String getStudentNum()
{
return studentNum;
}
public void setStudevtNum(String strStudentNum)
{
studentNum = strStudentNum;
}
}