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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章