In the earlier post Inheritance, we have already seen how all the child classes (Circle, Triangle and Rectangle) access the overridden methods, using the reference of the parent class (Shape). The compiler doesn't detect any difference, so there wouldn't be any compile time issues. When running the program, the JVM detects dynamically which class is referred to and accordingly the respective methods are called. This feature is called Polymorphism.
Same way, interface variables can refer its implementing classes. I have already shown this in the post Interfaces. The implementing classes (Triangle and Rectangle) are accessing the implemented methods, using the reference of the parent class (IPolygon).
No comments:
Post a Comment