Polymorphism, class member access control, static method/field

Overloading vs. overriding (Polymorphism)

  • Overloading
    • Between a class and its subclass or within the same class
    • Same method name, different parameters, return type can be different (Note that method signature does not contain return type, and a signature is the unique identifier of a method)
  • Overriding
    • Between a class and its subclass
    • Same method name, same parameter, same return type
    • Higher visibility (If the super class has some private methods, then a subclass does no inherit those methods. So nothing to do with overriding. If someone wants to call the supper class's overridden methods, use super.func() )


Access control to Java class member

check oracle website


Static method/field

check o'reilly tutorial

Why instance method can call static method or use static field in it enclosing class? Because static fields and methods exist from the class loading time. At the using time, the static ones already exist.

Why calling instance method or use instance field in the same class, we need first create an object (cannot use this.)? Instance exists only after object initialization. At the using time, the instance ones may not exist, so need to create them first.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值