zoukankan      html  css  js  c++  java
  • 20200722 千锤百炼软工人第十七天

    今天再写一个类

    是一个学生类

    但是有一个错误没有解决

    希望有大佬抬我一手

    这是Student类的实现

    package a20200722;
    public class Student {
     private char[] no;
     private char[] name;
     private int age;
     public static int sum = 0;
     Student(char[] a,char[] b,int c){
      int i,j;
      this.age=c;
      for(i=0;i<a.length;i++)
      {
       this.no[i]=a[i];
      }
      no[i+1]='';
      for(j=0;j<b.length;j++)
      {
       this.name[j]=b[j];
      }
      name[j+1]='';
      sum++;
      System.out.print("Constructor run");
      System.out.print("NumTotal:"+sum);
     }
     
     Student(Student a){
      int i,j;
      for(i=0;i<a.no.length;i++)
      {
       this.no[i]=a.no[i];
      }
      no[i+1]='';
      for(j=0;j<a.name.length;j++)
      {
       this.name[j]=a.name[j];
      }
      name[j+1]='';
      sum++;
      System.out.print("CopyConstructor run");
     }
     Student(){
      this.no=null;
      this.name=null;
      age=0;
      System.out.print("Constructor run");
     }
     public void finalize() {
      System.out.print("Destructor run");
      System.out.print("NumTotal:"+sum);
     }
     public void setNo(char a[]) {
      int i;
      for(i=0;i<a.length;i++)
      {
       this.no[i]=a[i];
      }
      this.no[i+1]='';
     }
     public void setNo() {
      this.no=null;
     }
     public void setName(char a[]) {
      int i;
      for(i=0;i<a.length;i++)
      {
       this.name[i]=a[i];
      }
      this.name[i+1]='';
     }
     public void setName() {
      this.name=null;
     }
     public char[] getNo() {
      return this.no;
     }
     public char[] getName() {
      return this.name;
     }
     public void setAge(int a) {
      this.age=a;
     }
     public void setAge() {
      this.age=0;
     }
     public int getAge() {
      return this.age;
     }
     public void show() {
      System.out.print("No:");
      for(int i=0;i<this.no.length;i++) {
       System.out.print(this.no[i]);
      }
      System.out.print(",Name:");
      for(int j=0;j<this.name.length;j++) {
       System.out.print(this.name[j]);
      }
      System.out.print(",Age:"+this.age);
     }
    }
    这是主函数的实现
    package a20200722;
    import a20200722.Student;
    public class Studentmain {
     public static void main(String[] args) { 
      char[] s1 = {'2','0','1','9','0','3','2','7'};
      char[] s2 = {'d','o','u','b','l','e','b','e','s','t'};
      Student stu1=new Student(s1,s2,0);
      stu1.setAge(21);
      stu1.show();
      Student stu2=stu1;
      stu2.setNo(s1);
      stu2.setName(s2);
      stu2.show();
      stu1=null;
      stu2=null;
      System.gc();
     }
    }
  • 相关阅读:
    常用linux命令及其设置
    shell脚本编写步骤及其常用命令和符号
    浏览器访问php脚本通过sendmail用mail函数发送邮件
    windows server 定期备份数据库脚本
    图片垂直水平居中
    "!function",自执行函数表达式
    jQuery(function(){})与(function(){})(jQuery) 的区别
    在Windows Server 2019通过Docker Compose部署Asp.Net Core
    Redis集群同步问题
    webapi跨域使用session
  • 原文地址:https://www.cnblogs.com/huangmouren233/p/13362190.html
Copyright © 2011-2022 走看看