Inheritance and polymorphism 1

  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!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值