Easy-to-Forget knowledge in java, occasionally updated ......, Regular update...

Source: Internet
Author: User

Easy-to-Forget knowledge in java, occasionally updated ......, Regular update...

If someone asks you: "Is it true that the subclass inherits all non-private attributes and methods of the parent class? "If you are right, I can only say too young too simple!

Modifier Problems

Why is this sentence incorrect? As long as you have figured out the application scope of the four access modifiers, you will know.

Public: access from anywhere

Private: Class accessors (get their own names), which can be accessed only in this class, but not in other classes.

Default: When the modifier is not added, it is the package access character, as long as it can be accessed in this package, other packages cannot be accessed (subclass in other packages cannot be accessed, this is exactly the same as protected)

Protected: The default value is + sub-class of the non-same package, that is, it can be accessed in this package and sub-class of the non-same package, but not in the non-sub-class of the non-same package.

You can write a case to verify it and help you better understand it. Then I will ask: "Is the implementation class 'inherited 'all non-private attributes and methods of the parent interface correct? "If you have been inspired by the above, you have to think carefully. first, this problem occurs because the attributes in the interface are modified by public static final by default, and the methods in the interface are modified by public abstract by default. Therefore, the interface does not have private attributes and methods, therefore, "the implementation class 'inherits all the attributes and methods of the 'parent interface" is correct.

How to verify it?

Static: verify whether the class name can be called directly in the Implementation class

Final: verify whether the attribute value can be modified in the implementation class.

Abstract: try to write a specific method in the interface.

Public: I don't need to mention that.

Other... will be updated later ......

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.