Polymorphism
- Automatic in Java, not true for C++ where programmer must include virtual keyword
- When a base class reference invokes a method
- The true type of the object being referred to is determined
- If the true type does not have a matching method, the base class method is executed
- If the base class doesn't have the method's interface, the program would not have compiled
- Can't call a method that is specific to a subclass via a base class reference
- If the true type oof the object is, in fact, a base class type, it will simple execute the base class method
Abstract Methods and Classes
- Force all subclasses to provide an implementation, specify the method is abstract in the base class
- Subclasses that don't implement the abstract method can not be compile
- Abstract methods don't have n implementation at he base class, since all subclasses are required to implement it, there is no need for a method body at the base class level
- A class that contains some abstract functions in an abstract class. In java, programmer must specify a class is abstract
- Cannot create objects of an abstract type
Final Methods and Classes
- Saying a method is final means the method cannot be overriden by a subclass
- Saying a class is final means the class may not be extended
Why do this?
- It's faster, compiler doesn't have to look up the method call tree