public class Student { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Student student=new Student();
//student.setstudent1Name(zhangsan);
//student.setstudentage(18);
System.out.print(student); }
public class student1
{
private String StudentName;
public String getStudentName() {
return StudentName;
}
public void setStudentName(String studentName) {
StudentName = studentName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
private int age;
}
}
编译出Student@1e5e2c3?为什么啊?
// TODO Auto-generated method stub
Student1 student=new Student1();
//student.setstudent1Name(zhangsan);
//student.setstudentage(18);
System.out.print(student); }
你想实例一个student1吧,你把人家实例对象打印出干神马啊??
public String toString()
{
return "年龄:"+agg+"姓名:"+ studentName;
}
public class Person { /**
* @param args
*/
private int Age;
public int getAge() {
return Age;
}
public void setAge(int Age) {
this.Age = Age;
}
private String Name;
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public class Person1
{
public void main(String[] args) {
// TODO Auto-generated method stub
Person p=new Person();
p.Age=18;
p.Name="zhangsan";
p.getAge();
p.getName();
}}
}
怎么回事?
System.out.println(stutent.getAge());
第二个问题:
p.Age=18;
p.Name="zhangsan";
错误,应改为
p.setAge(18);
p.setName(="zhangsan");