/**//*Java语言中,对象就是对一组变量和相关方法的封装,其中变量表明了对象的状态,方法表明了对象具有的行为。 *通过对象的封装,实现了模块化和信息隐藏。通过对类的成员施以一定的访问权限,实现了类中成员的信息隐藏。*/public class Student ...{ private String no; private String name; private String depart; private double tatol; private int grade; private int age; private boolean state; private boolean xuanxiu; public Student(double c,double m,double e,double co,boolean state)...{ Sort sort1=new Sort(); sort1.setChinese(c); sort1.setMath(m); sort1.setEnglish(e); sort1.setColligate(co); tatol=getTatol(sort1.getCount(),state); } public double getTatol(double cj,boolean y) ...{ if(y) return cj+10; else return cj; } public void getXuanxiu(String name,double tatol,int grade)...{ boolean temp=false; if((grade==4||grade==3)&&(tatol>500)) temp=true; if (temp) System.out.println(name+" 需要选修"); else System.out.println(name+" 不需要选修"); } public Student(Student st[]) ...{ int i,j; Student temp; for(i=0;i<st.length;i++)...{ for(j=0;j<i;j++)...{ if(st[i].tatol<st[j].tatol)...{ temp=st[i]; st[i]=st[j]; st[j]=temp; } } } System.out.println("成绩排序如下:"); for(i=0;i<st.length;i++) ...{ System.out.println("姓名:"+st[i].name+" 总分:"+st[i].tatol); } } public static void main(String[] args) ...{ Student stu[]=new Student[3]; stu[0]=new Student(90,90,90,300,true); stu[0].name="allen"; stu[0].no="18"; stu[0].age=12; stu[0].grade=3; stu[0].getXuanxiu(stu[0].name,stu[0].tatol,stu[0].grade); stu[1]=new Student(90,10,80,230,true); stu[1].name="bill"; stu[1].no="17"; stu[1].age=12; stu[1].grade=3; stu[1].getXuanxiu(stu[1].name,stu[1].tatol,stu[1].grade); stu[2]=new Student(90,10,20,300,true); stu[2].name="john"; stu[2].no="19"; stu[2].age=12; stu[2].grade=3; stu[2].getXuanxiu(stu[2].name,stu[2].tatol,stu[2].grade); Student student=new Student(stu); }}public class Sort ...{ private double chinese; private double math; private double english; private double colligate; public double count; void setChinese(double c)...{ this.chinese=c; } void setMath(double m)...{ this.math=m; } void setEnglish(double e)...{ this.english=e; } void setColligate(double co)...{ this.colligate=co; } public double getCount()...{ return chinese+math+english+colligate; }} //多态/**//* * 抽象类:用abstract关键字来修饰一个类时,该类叫做抽象类; * 抽象类必须被继承。 * 抽象类不能被直接实例化。它只能作为其它类的超类,这一点与最终类(final类)正好相反。 * 抽象方法:用abstract来修饰一个方法时,该方法叫做抽象方法。 * 抽象方法必须被重写 * 抽象方法只有声明,不能有实现。 * 定义了抽象方法的类必须是抽象类。 * */public abstract class Shape ...{ public abstract void draw(); public void test()...{ System.out.println("test.."); }}//抽象类必须被继承。继承了Shape 类public class Circle extends Shape ...{ public void draw()...{ //拥有自己的方法 System.out.println("Circle..."); }}//抽象类必须被继承。继承了Shape 类public class Opoint extends Shape ...{ public void draw()...{ System.out.println("Opoint..."); }}public class ShapeApp ...{ public void callDraw(Shape s)...{ s.draw(); }}public class clillShape ...{ public static void main(String args[])...{ ShapeApp sb=new ShapeApp(); Shape s=new Opoint(); System.out.println("s"); sb.callDraw(s); }}