* Quiz7 tomorrow in tutorial. * A3 extended to Fri Noon. * Office hours (all in BA2000): * Tuesday 12-1pm * Wednesday 11-12pm * Thursday 11-12pm //Review of Object Oriented (OO) Concepts and more detials: /*Recall: Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. An example would be a Car class You could create a generic Car class with states and actions that are common to all Cars. Then more specific classes could be defined for special cars like sport cars, 4wd, suv, etc. The generic class is known as the parent (or superclass or base class) and the specific classes as children (or subclasses or derived classes). The concept of inheritance greatly enhances the ability to reuse code as well as making design a much simpler and cleaner process. */ /*method overloading: Using the same method name but different signature (arg or return types) method overiding: Using the the same method signature (name, number of parameters and parameter types). When extending a class constructor you can reuse the superclass constructor and overridden superclass methods by using the reserved word super. e.g. super(x,y) which calls the super constructor or super.m(a,b) which calls method m in the supper class Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. This is a basic principle of object oriented programming. Overloading and overriding are two types of polymorphism . Now we will look at the third type: "dynamic method binding". Student s = new Student("Pam", 8923423); s.toString() StudentAthlete s1 = new StudentAthlete("Joe", 98023423, "Swimming") s1.toString() s1.getSport() StudentNerd s2 = new StudentNerd("Joe", 98023423, 25); s2.toString() s2.getSprot() //ooops! s2 is a StudentNerd, it has no knowlege of StudentAthlete class s2.readBook() s2.toString() s1.readBook() //oops! s1 is a StudentAthlete , it has no knowlege of StudentNerd class s.readBook() //oops! what's the problem? s.getSport() //oops! what's the problem? //here is the class hierarchy: Object | Student | / \ StudentAthlete StudentNerd Student s3 s3 = s1 //remember s1 (athelte) is a student s3.toString() s3.getSprot() s3 = s2 //remember s2 (nerd) is a student s3.toString() s3.readBook() StudnetNerd s4 s4 = s1 //oops! s1 is athlete which is not nerd so cannot assign!! StudnetNerd s5 s5 = s2 //oops! s2 nerd is which is not athlete so cannot assign!! //How do we know what object s refers to? we use isntanceof operator: s1 instanceof Object s1 instanceof Student s1 instanceof StudentAthlete s1 instanceof String s1 instanceof StudentNerd s2 instanceof Object s2 instanceof Student s2 instanceof StudentAthlete s2 instanceof String s2 instanceof StudentNerd //next lecture we talk about how cast these object into one another! //also about how to handle array of such objects.