• java 对象数组定义


    下面代码实现了定义一个数组对象

     1 public class Student {
     2 
     3     private String username;
     4     private int num;
     5 
     6     public Student(String username, int num) {
     7         this.username = username;
     8         this.num = num;
     9     }
    10 
    11     public static void main(String[] args) {
    12         Student s[] = new Student[10];
    13         for (int i = 0; i < s.length; i++) {
    14             s[i] = new Student(i + "", i);
    15             System.out.println(s[i]);
    16         }
    17 
    18     }
    19 
    20     public String getUsername() {
    21         return username;
    22     }
    23 
    24     public void setUsername(String username) {
    25         this.username = username;
    26     }
    27 
    28     public int getNum() {
    29         return num;
    30     }
    31 
    32     public void setNum(int num) {
    33         this.num = num;
    34     }
    35 
    36     @Override
    37     public String toString() {
    38         return this.num + " " + this.username;
    39     }
    40 
    41 }

    -

  • 相关阅读:
    X的平方根(二分)
    JavaScript(1)
    入门训练 Fibonacci数列 (水题)
    set集合容器
    deque双端队列容器
    回归分析
    cf1121d 尺取
    CF1121C 模拟
    poj3662 二分+最短路
    最短路小结
  • 原文地址:https://www.cnblogs.com/zhjsll/p/4381309.html
Copyright © 2020-2023  润新知