Inheritance and polymorphism 1

来源:互联网 发布:网络圣战 编辑:程序博客网 时间:2024/04/29 05:05
  The subclass inheritance all variables and methods from superclass. The subclass can have its own methods and variables, or it also can override the method of superclass. I think there is a relation with polymorphic. On the surface of polymorphism, we can have polymorphic arguments and return types, using the reference as arguments in method. I think one parameter is a reference variable of the superclass and the other is an object of the subclass, when we call the method, they link like declare an object and call the object's method. And because inheritance, if the subclass override the method, object will implement the overriden method; if it isn't, it will implement the method in superclass. Using overriding, implement polymorphism. The rules for overriding, the method must has the same arguments and return types. Overloading, however, is not the same as an overridde method. Its return types and arguments list must different, and the access level can be varied. Let's see two overload methods: public void setUniqueID(String theID){...};public void setUniqueID(int ssNumber){...}. They have different arguments, but they're both have no return, are they legal?
  These are not serious polymorphism, I just consider whether these relationship between superclass and subclass is the basis of interface. Tomorrow I will read the interfaces and abstract classes, maybe i'll more clearlier.Bother your time,I'm so sorry!Thanks a lot!