鱼C论坛

 找回密码
 立即注册
查看: 4462|回复: 5

对象数组的题目

[复制链接]
发表于 2020-5-20 11:12:44 | 显示全部楼层
main方法是静态的,而Student内部类是动态的,你把Student类加上static修饰就可以了。
如果你不想加static修饰可以先new一个StudentText对象出来,再通过这个对象把内部类的对象new出来
  1. public class StudentText  {
  2.         public static void main(String[] args) {
  3.                 Student[] stus=new Student[20];
  4.                 StudentText t= new StudentText();
  5.                 for (int i = 0; i < stus.length; i++) {
  6.                         stus[i] = t.new Student();
  7.                         stus[i].number=(i+1);
  8.                 }
  9.         }
  10.          class Student{
  11.                 int number;
  12.                 int state;
  13.                 int score;
  14.         }
  15. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-29 04:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表