码迷,mamicode.com
首页 > 编程语言 > 详细

java3- class student

时间:2015-10-21 22:47:04      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:

 1 package one;
 2 import java.util.*;
 3 import java.text.*;
 4 class person{
 5     public String name;
 6     public Date birthday;
 7     public String sex ,province,city;
 8     private static int count=0;
 9     public person (String name,Date birthday,
10             String sex,String province,String city){
11         this.name=name;
12         this.birthday=birthday;
13         this.sex=sex;
14         this.province=province;
15         this.city=city;
16     }
17     public person(String name,Date birthday){
18         this(name,birthday,"","","");
19     }
20     public person(){
21         this("",null);
22     }
23     public person (person p){
24         this.set(p.name,p.birthday,p.sex,p.province,p.city);
25     }
26     
27     public void finalize(){
28         System.out.println("释放对象("+this.toString()+")");
29         person.count--;
30     }
31     public String toString(){
32         return name+","+(birthday==null?"":birthday.toString())+","+
33             (sex==null?"":sex)+","+(province==null?"":province)+
34             (city==null?"":city);
35     }
36     public void set(String name,Date birthday,String sex,String province,
37             String city){
38         this.name=name==null?"":name;
39         this.sex=sex==null?"":sex;
40         this.province=province==null?"":province;
41         this.city=city==null?"":city;
42         Calendar calendar=new GregorianCalendar(0000,00,00,0,0,0);
43         Date date=calendar.getTime();
44         this.birthday=birthday==null?date:birthday;
45     }
46     public static void howMany(){
47         System.out.println(person.count+"个 person 对象");
48     }
49 }
50 
51 public class Student extends person {
52     public String department;
53     public String number;
54     public String speciality;
55     public boolean member;
56     private static int count=0;
57     public Student(String name,Date birthday,String sex,String province,
58             String city,String number,String department,String speciality,
59             boolean member){
60         super.set(name, birthday, sex, province, city);
61         this.set(number,department,speciality,member);
62         count++;
63     }
64     public void set(String number,String department,String specilality,
65             boolean member){
66         this.number=number==null?"":number;
67         this.department=department==null?"":department;
68         this.speciality=speciality==null?"":speciality;
69         this.member=member;
70     }
71     public void finalize(){
72         super.finalize();
73         Student.count--;
74     }
75     public Student(person p,String number,String department,String speciality,
76             boolean member){
77         this(p.name,p.birthday,p.sex,p.province,p.city,number,department,
78                 speciality,member);//this 后面没有点
79     }
80     public Student(Student s){
81         this(s.name,s.birthday,s.sex,s.province,s.city,s.number,
82                 s.department,s.speciality,s.member);
83     }
84     public static void howMany(){
85         person.howMany();
86         System.out.println(Student.count+"个 student对象");
87     }
88     public String toString(){
89         return super.toString()+","+department+","+speciality+","+number+
90                 ","+(member?"团员":"");
91     }
92     public static void main(String[] args) {
93         // TODO Auto-generated method stub
94 
95     }
96 
97 }

 

java3- class student

标签:

原文地址:http://www.cnblogs.com/linkzijun/p/4899108.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!