这段代码中的构造方法又没有问题。
------解决方案--------------------
有问题
参数里char studentname[20]什么意思?
------解决方案--------------------
this.studentname[20]=studentname[20]; 这就是个语法错误。
大小为20,访问下标为20的元素,怎么会没问题?
------解决方案--------------------
楼主 C 转过来的吧,还是好好学学 Java 吧。
- Java code
public class Person { private int studentno; private int teacherno; private String studentname; private String teachername; private int mark; public Person(int studentno, String studentname, int mark) { this.studentno = studentno; this.studentname = studentname; this.mark = mark; System.out.println(studentno + studentname + mark); } public Person(int teacherno, String teachername) { this.teacherno = teacherno; this.teachername = teachername; System.out.println(teacherno + teachername); } public static void main(String[] args) { //int x,z; //char y[]=new char[20]; //System.out.println("input"); Person r = new Person(1, "", 1); Person r1 = new Person(2, ""); }}