[ java ] in KIDS 글 쓴 이(By): iknowyou (Coffeeman) 날 짜 (Date): 1997년11월13일(목) 20시26분47초 ROK 제 목(Title): [polymorphism in JAVA]Student.java public class Student extends Object implements Comparable { int id; String name; public Student(int id, String name ){ this.id = id; this.name = name; } public void setID(int id){ this.id = id; } public void setName(String name){ this.name = name; } public int getID(){ return id;} public String getName(){ return name;} //sort 하려면 이부분이 해당객체에 반드시 있어야한다. public int compare(Comparable c){ - Student s = (Student)c; // 비교 대상이 Pfofessor이라면 if( c == instanceof ... )을 //하면 된다. if( this.id < s.getID() ) return -1; else if( this.id == s.getID() ) return 0; else return 1; } } class Life extends Object implements Dynamic { Life(Life father, Life mother){} responseToThis(Life this){} responseToOthers(Life others){} } |