java技术博客

jsp博客
数据加载中……
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;
}
}

posted on 2008-10-21 19:16 郭兴华 阅读(78) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: