package yingyong;

public class yingyong {

public static class person{           //static需要特别引起注意,不能去掉!!!!!

        public int age;

        public int height;

        public void show()

        {

            System.out.println("我的年龄是:"+age+","+"我的身高是:"+height);

        }

    }

    public static void main(String[] args) {

        // TODO Auto-generated method stub

       person[] student;

       student=new person[2];

      

       person lee=new person();   

       lee.age=22;

       lee.height=178;

       person zhang=new person();

       zhang.age=18;

       zhang.height=185;

       student[0]=zhang;

       student[1]=lee;

       for(int i=0;i<2;i++)

       {

           student[i].show();

       }

    }


}

结果如下

Java引用

注意如果去掉static,会出现

Java引用

 

相关文章:

  • 2022-01-09
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-11-26
  • 2021-11-10
  • 2021-09-11
猜你喜欢
  • 2021-07-20
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
相关资源
相似解决方案