permission size for four rights modifiers (public, protected, default, private)
Note: Default, does not have this keyword, it thinks that defaults, that is, nothing added!
Generally, the default visibility is package visibility (package visibility).
|
This class |
under the same package (subclasses and unrelated classes) |
under different packages (subclasses) |
under different packages (unrelated classes) |
Private |
Y |
|
|
|
Default |
Y |
Y |
|
|
Protected |
Y |
Y |
Y |
|
Public |
Y |
Y |
Y |
Y |
summary of common modifiers used by classes and their composition in object-oriented
Modifiers:
permission modifiers: private, default, protected, public
status modifier: Static, Final
abstract modifier: Abstract
1. Class:
Permission modifiers: default,public
status Modifiers: final
abstract modifier: Abstract
The most used is: public
2. Member variables:
permission modifiers: private, Default,protected,public
State modifier: The
most used static,final is: Private
3. Construct method:
permission modifier: Private,default, Protected,public
uses the most is: public
4. Member Method:
permission modifier: private,default,protected,public
Status modifiers: static,final
Abstract Modifiers: Abstract The
most used is: public
5. Other than the combination of rules:
member variables: public static final
Member method: Public
static public
abstract public
final
related note points:Abstract cannot co-exist with the following keywords
Private
(When the class and member method is decorated, if there is an abstract method in the abstract class, it should be inherited by the quilt class, and all the abstract methods of the parent class are overridden in the subclass, and the class cannot be inherited, the member method cannot be accessed) final
(For the reason above, when the final modifies the class and member methods, the class cannot be inherited and the Member method cannot be overridden) static
(If you decorate with static, you only pass the "class name." You can call the abstract method directly, obviously, it doesn't make any sense. When all member methods in a class are static (all static), the constructor must be private (plus private).
(Example: In Java.lang, the Math class calls its constants and static methods –math.pi and Math.Abs (a) directly without creating objects)
Summary
In the object-oriented, three characteristics (encapsulation, inheritance, polymorphism) of the understanding is particularly important, but at the same time understand the four kinds of permissions modified relationship, for who can call who, whether there is access rights and other issues, to solve more handy! Of course, this article is the first time I used Markdown Editor to write in Csdn, it feels good!
This article address: http://blog.csdn.net/menglanyingfei/article/details/55210673
This article originates from: http://blog.csdn.net/menglanyingfei?viewmode=contents
I hope that you can comment and guide my article to communicate and learn from each other, but also welcome you to my blog to see the article you have helped, but also welcome to reprint, but I would like to indicate the origin of the hyperlink in the clear location! Thank you!