Polymorphism, class member access control, static method/Field

Source: Internet
Author: User

Overloading vs. Overriding (polymorphism)

    • Overloading

      • Between a class and its subclass or within the same class
      • Same method name, different parameters, return type
        CanBe 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.