现在的位置: 首页 > 综合 > 正文

Polymorphism, class member access control, static method/field

2013年10月15日 ⁄ 综合 ⁄ 共 985字 ⁄ 字号 评论关闭

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.

抱歉!评论已关闭.