Java access levels (access control)

Source: Internet
Author: User
Tags modifier modifiers reflection

Access levels Package World
Modifier Class Subclass
Public Y Y Y Y
Protected Y Y Y N
No modifier Y Y N N
Private Y N N N

The following table shows where the members of the Alpha class is visible for each of the access modifiers that can is AP Plied to them.
Https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

Modifier Alpha Beta alphasub Gamma
Public Y Y Y Y
Protected Y Y Y N
No modifier Y Y N N
Private Y N N N

Turns out I've been doing the opposite.
The visibility of protected is actually greater than the package. I've been wrong about the internship interview.

The essence of Access levels

If you had a field that's private it means no other class can get on it. wrong! If you really want to your can subvert the access control mechanisms in almost any language. Usually the through is via reflection. The rationale is this debuggers and other system tools often need to see private data, so usually the reflection INTERFAC Es allow you to does this.
C + + doesn ' t has this kind of reflection, but there can just use direct memory manipulation since C + + is fundamentally Open memory.
The point of access control isn't to prevent access, but more to signal that the class prefers to keep some things to its Elf. Using access modifiers, like so many things in programming, is primarily about communication.
Http://martinfowler.com/bliki/AccessModifier.html

It is an expert, said the words are too level!
I understand that access control is actually compiled at compile time, something like a macro definition and does not have a runtime check.
I don't know if this understanding is wrong. I haven't found a way to verify this point for the time being. I hope someone can give a concrete statement.



From for notes (Wiz)



Java access levels (access control)

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.