StudentTest1.java
/*
*学生类,包括学生的基本信息
*/
public class StudentTest1{
public static void main(){
Student1 tom=new Student1("Tom","20020410");
Student2 jack=new Student2("jack","20030911");
System.out.println(jack.toString());
System.out.println("通过公开字段,修改实例字段值。")
//tom.strName='唐僧";
jack.strName="孙悟空";
System.out.println(jack.toString());
}}
class Student1{
private String strName="";
private String strNumber="";
public Student1(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public String getStudentNumber(){
return strNumber;
}
public String toString(){
return "student="+strName+",student number="+strNumber;
} }
class Student2{
public String strName="";
public String strNuber="";
public Student2(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;}
public String getStudentNumber(){
return strNumber;
}
public String toString(){
return "学生姓名="+strName+",学号="+strNumber;
}
}
*学生类,包括学生的基本信息
*/
public class StudentTest1{
public static void main(){
Student1 tom=new Student1("Tom","20020410");
Student2 jack=new Student2("jack","20030911");
System.out.println(jack.toString());
System.out.println("通过公开字段,修改实例字段值。")
//tom.strName='唐僧";
jack.strName="孙悟空";
System.out.println(jack.toString());
}}
class Student1{
private String strName="";
private String strNumber="";
public Student1(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public String getStudentNumber(){
return strNumber;
}
public String toString(){
return "student="+strName+",student number="+strNumber;
} }
class Student2{
public String strName="";
public String strNuber="";
public Student2(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;}
public String getStudentNumber(){
return strNumber;
}
public String toString(){
return "学生姓名="+strName+",学号="+strNumber;
}
}