public class programe {
public static class Student // 去掉public static ,下面的语句:
//Student stu = new Student("lxr","10060",'b',20); 出现语法错误,求解
{
static int studentSum; //还有就是这里有出现语法错
String name;
String id;
char sex;
int age;
Student ()
{
name = "null";
id = "null" ;
sex = 'n';
age = 0;
}
Student (String _name,String _id,char _sex,int _age)
{
name = _name;
id = _id ;
sex = _sex;
age = _age;
}
public void setName(String _name){ name = _name;}
public void setId(String _id){ id = _id;}
public void setSex( char _sex){ sex = _sex;}
public void setAge( int _age){ age = _age;}
public static void setStudentSum(int sum)
{
studentSum = sum;
System.out.print("student sum = "+studentSum);
}
public void showStudentInfo()
{
System.out.println("Name : "+ this.name +"\n" + "ID : "+this.id);
System.out.println("Sex :"+this.sex +"\n"+ "Age :"+this.age);
};
}
public static void main(String[] args) {
Student stu = new Student("lxr","10060",'b',20);
stu.showStudentInfo();
stu.setAge(21);
stu.showStudentInfo();
Student.setStudentSum(10);
}
}
------解决方案--------------------
一股浓浓的C/C++编码风格味道。