java中一切都是用class来做,定义一个class.按你要求的数据类型做一些东西就是了,

解决方案 »

  1.   

    可是class 不能用数组吧?
      

  2.   

    class SuperType {
        int member1;
        int member2;
        ...
    }
      

  3.   

    class Test{
        int[] array;
    }
      

  4.   

    在 Java 中 数组 也是作为一个 对象 来处理的
      

  5.   

    java中什么是数据类型啊,everything is object,也就是数据类型即使java中简单的数据类型也有它自己的包装类,比如int 对应的Integer,boolean对应的Boolean.类就是数据类型呀
    你在用java写java就是在不停的创建使用自己的数据类型
      

  6.   

    不能用啊,比如不能这样:

    test[] Mytest;
    class test
    {
      int a;
       }
      

  7.   

    下面我编的一段代码,编译通过但运行出错:
    import java.io.*;
    public class test
    {
      int num;
      info[] kkk;  public static class info 
      {
        int count;
        info(){count=0;}
         }
          
      public test() 
        {   
         int i;
            num=0;
            for(i=0;i<2;i++)
            {
             kkk=new info[2];
             }
            kkk[i].count=1;
         kkk[1].count=2;
         }
        
      public static void main(String[] args)
        {
         test p=new test();    
         System.out.println(p.kkk[1].count);    
         } 
    }
      

  8.   

    这是什么东东?
    main函数中的数组下标是 l 还是 1 ?
      

  9.   

    问题出在这里
            for(i=0;i<2;i++)
            {
             kkk=new info[2];
             }
            kkk[i].count=1;
    你已经定义了数组的大小为2,其中只能有2个元素,最大下标为1,就是说其中元素为info[0]和info[1]循环在i=2时退出,而你又用了 kkk[i].count=1;在此i=2,也就是kkk[2].count,当然会出错
      

  10.   

    不好意思,刚刚代码贴错了,是这样的:
    import java.io.*;
    public class test
    {
      int num;
      info[] kkk;  public static class info 
      {
        int count;
        info(){count=0;}
          }
       
      public test() 
        {   
         int i;
            num=0;
            kkk=new info[2];        
            kkk[0].count=1;
         kkk[1].count=2;
         }
        
      public static void main(String[] args)
        {
         test p=new test();    
         System.out.println(p.kkk[1].count);    
         } 
    }
    运行出错:java.lang.NullPointerException
    at test.<init>(test.java:24)
    at test.main(test.java:30)
    Exception in thread "main" 
      

  11.   

    应该这样
    kkk=new info[2];
    kkk[0] = new info();       
    kkk[0].count=1;
    kkk[1] = new info();
    kkk[1].count=2;