Easy-to-forget knowledge in Java, not updated regularly ...

Source: Internet
Author: User

If someone asks you, "Does the subclass inherit all non-private properties and methods of the parent class?" "If you answer right, then I can only say too young too simple!

modifier Problems

 Why is that wrong, as long as you figure out the scope of application of the 4 access modifiers you'll know.

  Public: can be accessed anywhere

Private: class accessor (own name), as long as it is accessible in this class, cannot be accessed in other classes

Default: That is, when the non-modifier, this is the package accessor , as long as in this package can be accessed, the other package can not be accessed (the subclass in other packages can not be accessed, which is the difference between protected)

Protected: The default + subclass of the non-identical package, which can be accessed in this package and the subclasses of the non-identical package, cannot be accessed in the non-identical class

You can write a case to verify your own, but also help yourself to better understand, then I asked: "Implement the class ' inherit ' the parent interface of all non-private properties and methods, right?" "If you're being inspired to blurt out ' wrong ', then you need to think about it. First of all, this problem is problematic because the properties in the interface are default to public static final decoration, the methods in the interface are modified by default public , so the interface does not have private properties and methods, so that "implementation class ' Inherit ' All properties and methods in the parent interface are right.

How to verify it?

Static: Verify that the class name can be called directly in the implementation class

Final: Verify that the value of the property can be modified in the implementation class

Abstract: Try to write a specific method in the interface

Public: Let's not say that.

  

There will be other updates later ...

Easy-to-forget knowledge in Java, not updated regularly ...

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.