What are access modifiers in Java EE
Access modifiers are always used when writing Java code. So what's the difference between the four access modifiers? When is the appropriate modifier used? Today, learn more about the difference between these four modifiers.
Four Java modifiers: public, protected, default, private. In this order, the scope of the modifier can be reduced one after the other. To put it in a table:
To check the form's correctness and better understanding, let's test it with code.
First, let's check that all four modifiers can play a role in the same category.
This shows that the four modifiers can all play the same role.
In the same package (subclasses and other classes):
We can see that there is no test4 () method of the parent class in the subclass. Therefore, private cannot be applied to subclasses. What happens if we set up a s.test4 ()?
This also confirms the conclusion given in the table that private cannot work in subclasses of the same package.
We can see that there is no inheritance from the parent class in the same package, meaning it is not a subclass of it, and private cannot work either.
In another package (subclass and other classes):
The following describes the situation in the same package. Next, let's test the effects of the four modifiers in different packages.
The first is the subclass in different packages:
We can see that in various packages only the public and protected subclasses of the class can have an effect.
What happens in other packages besides non-subclasses?
OK, the result is already obvious.
OK, except for the public, the other three are all GG.
By demonstrating the code, the different areas of the four access modifiers were shown. I think it's better to understand these four modifiers.
Until this year's Spring Festival, insist on writing at least three blogs a week, knowledge of JavaSE, JavaEE, computer network or data structure. Adding a small tail can be considered to help crowd yourself.
If you come around and find it useful, you might want to give it a thumbs up. Look at that thumbs up, it's long and wide ~~~~~~>
- What is a natural eyelash lift
- What is a tin scream
- Is it wrong to kill yourself?
- What is an event management plan
- What is sterile filtration
- How do I identify fundamentally strong stocks
- Air pollution causes global warming
- Which living plants can match goldfish?
- What does that mean in mathematics
- What is the temperature of the groundwater
- Can lead oxide be reduced by hydrogen
- What is a Psychometric Career Test
- Business loans for women
- How did you prepare for ANTHE
- How does manifestation magic work
- Where do the Bayesian priors come from
- Ibuprofen will take stunt growth
- Why is YouTube more popular than Dailymotion
- How porn humiliates women
- Which IIT contain aeronautical engineering
- What is the first rock and roll group
- What is a decomposer in biology
- Should robots be designed like humans
- What does the Punjabi word Kokka mean
- Are brass instruments harder than wooden ones
- Electrolysis can occur in nature
- Why do Ugandans want to be famous
- Will the rust belt ever recover?
- Will enter Gully Young 300 Cr Club
- How does a person get Lyme disease
- Why does al Assad speak good English
- Why is it called Ground Zero Mosque
- What is a state payment plan
- How do I edit with the Video Toolbox