Java basics: Access domains, polymorphism, etc.

Source: Internet
Author: User

Java reuse mechanisms include override, overload, hide, and shadow.

Override overwrite. The subclass overwrites the same parameter method of the parent class.
Overload, similar methods with different parameters of the same name
Hide hiding means that the static method of the parent class is "hidden, so it is exempt from quilt overwriting". formally, the static method of the same name and parameter of the Parent and Child classes is hide; in principle, the static method does not belong to the object but belongs to the class, so there is no concept of inheritance. In terms of usage, the static method is called directly by class, and there is no polymorphism!
Shadow masking, for example, hiding variables with the same name in a method

The access control of Java is divided into four fields, which are very simple (listed in ascending order ):
Public Global Access
Protected inherits accessible
The default (that is, the domain is not explicitly specified) package can be accessed inside
Private class internal access
Child inheritance cannot "narrow down" the fields of the parent method. For example, the method of the parent protected class cannot overwrite the method of the quilt class "default", because the access domain of protected is considered to be greater than the "default"

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.