// Real extension methods, supporting dynamic dispatch // add new methods to classes, change inheritance relation between // classes.. // start with a regular java subclass and interface: class studentathlete extends student { String sport = "basketball"; public studentathlete(String n) { super(n); } public void run() { System.out.println("whoooosh!"); } } interface stuinterface { int tuition(); // new method to add } ////// add tuition method to student and subclass studentathlete: privileged aspect extendstudent // privileged can access private fields (gpa) { //change subtype relationship with declare parents: declare parents: student implements stuinterface; // now *obligated* to extend student classes public int student.tuition() { if (this.gpa>3.7) return 10000; // scholarship student else return 40000; } public int studentathlete.tuition() { return 0; } // all student athletes are on scholarship // changing main without changing main... after() : execution(public static void *.main(String[])) { student s1 = new studentathlete("F. Asta Nimal"); System.out.println(s1.name+"'s tuition is "+s1.tuition()); // dynamic dispatch on new method? YES } }//extendstudent privileged aspect