A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 安静的喝会奶 中级黑马   /  2016-6-15 09:39  /  295 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class  Arrobject
{
        public static void main(String[] args)
        {
        Student[] students = new Student[4];
            students[0] = new Student("lin",24);
            students[1] = new Student("wu",24);
            students[2] = new Student("huang",21);
            students[3] = new Student("zhou",21);
            System.out.println("姓名"+"\t\t"+"年龄");
            getmassage(students);
        }
        public static void getmassage(Student[] students)
        {
           for(int i=0;i<students.length;i++)
           {
                Student s = students[i];
                int age = s.getAge();
                String name = s.getName();
                System.out.println(name+"\t\t"+age);
           }
        }
}
class Student
{
    private int age;
    private String name;
    public Student(String name,int age)
    {
        this.name = name;
        this.age = age;
    }
    public int getAge()
    {
        return age;
    }
    public String getName()
    {
        return name;
    }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马