package com.edu.common.demo;public interface Istudy { void learnJava();}
package com.edu.common.demo;import java.util.ArrayList;import java.util.Iterator;import java.util.List;public class MainJava { public static void main(String[] args) { Student stu1 = new Student("zhangsan",20); Student stu2 = new Student("lisi",21); Student stu3 = new Student("wangwu",20); List<Student> stuList = new ArrayList<>(); stuList.add(stu1); stuList.add(stu2); stuList.add(stu3); Iterator it = stuList.iterator(); while (it.hasNext()){ Student s=(Student)it.next(); s.learnJava(); s.printInfo(); }// Iterator it=students.iterator();// while(it.hasNext()){// Student s=(Student)it.next();// System.out.println("编号:" + s.ID + "\t\t\t姓名:" + s.name + "\t\t\t年龄:" + s.age + "\t\t\t性别:" + s.gender);// } }}
package com.edu.common.demo;public abstract class People { private String name; private int age; public void setName(String name) { this.name = name; } public String getName() { return name; } public void setAge(int age) { this.age = age; } public int getAge() { return age; } protected abstract void printInfo();}
package com.edu.common.demo;public class Student extends People implements Istudy{ public Student(String name,int age){ super.setName(name); super.setAge(age); } @Override public void learnJava() { System.out.println("I have learned java."); } @Override public void printInfo() { System.out.println("student:"+getName()+";age:"+getAge()); }}