20200723 千锤百炼软工人第十八天

今天完成了昨天的程序

改完了那个程序

在此附上代码和截图

Stundent类的代码

package a20200723;
public class Student {
 private String name;
 private String no;
 private int age;
 private static int sum=0;
 public String getNo() {
  return no;
 }
 public String getName() {
  return name;
 }
 public int getAge() {
  return age;
 }
 public void setNo(String no) {
  this.no = no;
 }
 public void setName(String name) {
  this.name = name;
 }
 public void setAge(int age) {
  this.age = age;
 }
 public Student() {
  this.no=null;
  this.name=null;
  this.age=0;
  sum=sum+1;
  System.out.print("Constructor run\n");
  System.out.print("NumTotal:"+sum+"\n");
 }
 public Student(String no,String name, int age) {
  this.name = name;
  this.age = age;
  sum=sum+1;
  System.out.print("Constructor run\n");
  System.out.print("NumTotal:"+sum+"\n");
 }
 public void show(){
  System.out.println("我叫"+name+",我今年"+age+"岁\n");
 }
 pubhli'zc v'yoizd finalize() {
  sum=sum-1;
  System.out.print("Destructor run\n");
  System.out.print("NumTotal:"+sum+"\n");
 }
}
 
主函数代码
  package a20200723;
import a20200723.Student;
public class main {
 public static void main(String[] args)
 {
 String s1="20190327";
   String s2="doublebest";
   Student stu1=new Student(s1,s2,0);
   stu1.setAge(21);
   stu1.show();
   Student stu2=new Student();
   stu2=stu1;
   stu2.setNo(s1);
   stu2.setName(s2);
   stu2.show();
   stu1=null;
   stu2=null;
   System.gc();

}
截图
    
posted @ 2020-07-23 18:55  黄某人233  阅读(95)  评论(0编辑  收藏  举报